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;}
- hdu 3753 模拟
- 【几何模拟】hdu 3286
- hdu 1020 Encoding(模拟)
- hdu 1303 Doubles(模拟)
- hdu 4020 模拟
- HDU **** 暴力模拟
- HDU 4068 模拟
- HDU 4121 模拟
- 【模拟】HDU 4134
- HDU-1279 模拟
- HDU-1035 模拟
- HDU-1283 简单模拟
- HDU-1263 模拟
- hdu 4140 模拟
- hdu 1034 #模拟
- hdu 4194#模拟
- hdu 4350 Card 模拟
- hdu 4393 贪心+模拟
- android开发环境及java JDK开发环境搭建
- USACO section 3.1 Stamps(dp)
- Fast Colored TextBox for Syntax Highlighting(用于语法高亮的快速着色TextBox)
- 喜欢的歌、静静地听。喜欢的人、远远的看
- Zend framework创建
- hdu 3753 模拟
- [构造] 能量棒 energy
- 主流PHP框架间的比较(Zend Framework,CakePHP,CodeIgniter,Symfony,ThinkPHP,FleaPHP)
- 最大概率选择到“最好女孩”的算法
- Ubuntu 12.04安装/设置ibus-pinyin
- 如果我们分手了:伤感日志
- 放苹果问题
- Delphi7怎么样调用系统语音库 .
- 一些著名的开源项目