hdu 3753 模拟

来源:互联网 发布:网络十大丑男恶搞图片 编辑:程序博客网 时间:2024/06/05 09:09

题目讲输入时可能有leading spaces and trailing spaces ,'@' in a single line是case separated symbol 

然后就被坑了,  有些输入是以‘@’开头的,如果直接判断str[0]=='@'就WA了

我就是牺牲者哭,好像挺明显的东西,只有我这种挫人才跳进坑里


这几天遇到的还有给你case的数目,case separated with a blank line ,然后就是最后一个case不用endline

然后我又牺牲了


学习了~~


#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;char a[1050][300];char str[100000];int ans[2000];int get_nextword(int pos,char *s) {while(s[pos]!=' '&&s[pos]!='\0')pos++;return pos;  // return pos is whitespace }int print_word(int pos,char *s){while(s[pos]!=' '&&s[pos]!='\0')printf("%c",s[pos++]);return pos;  // pos now is whitespace}bool isend(char *s){if(strlen(s)==1&&s[0]=='@')return true;return false;}int main (){//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);int test;scanf("%d",&test);getchar();while(test--){int len,st,ed,n=0;memset(ans,-1,sizeof(ans));while(gets(str)!=NULL){//if(str[0]=='@')//break;    if(isend(str))    // 爹就是在这里坑的break;len=strlen(str);st=0;ed=len-1;for(int i=0;i<len;++i)if(str[i]!=' '){st=i;break;}for(int i=len-1;i>=0;--i)if(str[i]!=' '){ed=i;break;}str[ed+1]='\0';strcpy(a[++n],str+st);int pos=0,cnt=1;int nxt;while(a[n][pos]!='\0'){nxt=get_nextword(pos,a[n]);if(ans[cnt]<nxt-pos)ans[cnt]=nxt-pos;cnt++;pos=nxt;if(a[n][pos]=='\0')break;while(a[n][pos]==' ')pos++;}}for(int i=1;i<=n;++i){int pos=0,cnt=1,last=0;while(1){pos=print_word(last,a[i]);if(a[i][pos]=='\0')break;int t=pos-last;while(t<ans[cnt]+1)printf(" "),t++;cnt++;while(a[i][pos]==' ')pos++;last=pos;}printf("\n");}}//system("pause");return 0;}


原创粉丝点击