练习操作字符串的好题。
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int SIZE=5000+16; void fun_in(char s[]) { char a[SIZE]={‘\0‘}; while(scanf("%s",a),strcmp(a,"START")); while(gets(a),strcmp(a,"END"))//精华 如果直接输入回车则a[0]为‘\0‘, gets()以回车作为结束输入 scanf()以空格作为结束输入 { if(a[0]!=‘\0‘) strcat(s,a); else strcat(s,"\n"); } } void clean(char s[]) { char a[SIZE]={‘\0‘}; int k=0; for(int i=0;s[i];i++) { if(s[i]==‘ ‘||s[i]==‘\t‘||s[i]==‘\n‘) continue; a[k++]=s[i]; } strcpy(s,a); } const char* fun_out(char s1[],char s2[]) { if(strcmp(s1,s2)==0) return "Accepted"; clean(s1),clean(s2); if(strcmp(s1,s2)==0) return "Presentation Error"; return "Wrong Answer"; } int main() { int T; scanf("%d",&T); getchar(); while(T--) { char s1[SIZE]={‘\0‘}; char s2[SIZE]={‘\0‘}; fun_in(s1),fun_in(s2); printf("%s\n",fun_out(s1,s2)); } return 0; }
时间: 2024-11-02 01:30:11