PAT甲级考前整理之一网址:https://www.cnblogs.com/jlyg/p/7525244.html,主要总结了前面131题的类型以及易错题及坑点。
PAT甲级考前整理三网址:https://www.cnblogs.com/jlyg/p/10364727.html主要是讲132题开始的题目。
考前注意:
1、写函数(有返回值的函数)容易忘记返回值,可能本地运行没问题,但是提交了就会有问题。
2、不要把strlen()函数写到for、while的循环中,有时候会超时,最好是 int len = strlen(str);提前求出来。
3、用sort比较的时候,比较函数 int comp(const ST& st1,const ST& st2);如果在comp中调用ST的fun函数,fun函数必须加上const,例子 int fun()const{return 0;}
4、二位数组初始化不要直接赋值,比如int a[10][10] ={0},是错误的,应该使用memset(a,0,sizeof(a));(一维数组也最好不要直接复制,通过循环复制最好)
5、不要使用gets,PAT系统不支持。可以使用fprintf,使用fprintf注意最后一个字符是'\n',特别是比较的时候就不相等了。使用这一类函数时,注意需要把前一个输入的'\n'使用getchar去掉。
string mygets() { char str[300]; fgets(str,sizeof(str),stdin); int len = strlen(str); if(str[len-1]=='\n') str[len-1] = '\0'; \\最后一行可能没有换行符 return str; }
6、使用freopen("1.txt","r",stdin);来减少测试的时间。因为PAT里有定义ONLINE_JUDGE,所以你需要背一下,写错就没办了。用以下代码就无需在提交的时候修改就能提交(节约大量时间呀!!)
#include<iostream> #include<cstdio> #include<set> #include<map> #include<vector> #include<iterator> #include<algorithm> #include<cstring> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("test.txt","r",stdin); #endif // ONLINE_JUDGE return 0; }