码迷,mamicode.com
首页 > 其他好文 > 详细

HDOJ1073(gets 应用)

时间:2015-08-02 18:06:04      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

练习操作字符串的好题。

#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; }

 

HDOJ1073(gets 应用)

标签:

原文地址:http://www.cnblogs.com/program-ccc/p/4696277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!