例题I 回文串没有难度,从[0到len/2-1]就可以
#include<stdio.h> #include<string.h> bool pd(char a[]) { int len=strlen(a); if(len==0||len==1) return true; for(int i=0;i<=len/2-1;i++) { if(a[i]!=a[len-i-1]) return false; } return true; } int main() { char a[1000]; while(scanf("%s",a)!=EOF) { bool ans=pd(a); if(ans==true) printf("YES\n"); else printf("NO\n"); } return 0; }
PAT B1009
题本身没有什么难度,但是需要注意,不能直接在scanf("%s",&temp[len++])!=EOF这么写,因为这样的话最后一次等于EOF里面也会实现len++(因为前面的语句成功执行了),还有就是%s会自动跳过空格和回车,写不写getchar没什么区别
#include<stdio.h> #include<string.h> int main() { char temp[100][100]; int len=0; while(scanf("%s",&temp[len])!=EOF) { len++; getchar(); } for(int i=len-1;i>0;i--) { printf("%s",temp[i]); printf(" "); } printf("%s",temp[0]); return 0; }
时间才能证明一切,选好了就尽力去做吧!