poj1598(字符串处理)
来源:互联网 发布:时间矩阵图 编辑:程序博客网 时间:2024/05/21 07:06
从早上9点搞到现在:
总结几点 1:要保证输出顺序不便
2:吸收多余空格;
3:题目最后一行输出有问题直接用EOF结束
4:key (aba) aaba...aba....abaaba....答案是一;
5:注意循环不要有死循环;
#include <iostream>#include<cstring>#include<cstdlib>#include<string>#include<cstdio>#include<queue>#include<stack>#include<vector>#include<cctype>#include<map>#include<list>#include<set>#define INF 1<<28using namespace std;struct node{ int sum,no; char s[200]; char s1[200];} str1[220];char str[220][200];int n,k,Case=1;void pb(int i){ for(int j=0;str1[i].s1[j]!='\0';j++) { for(int l=0;l<n;l++) { int f=1,m; for( m=0;str[l][m]!='\0';m++) if(str[l][m]!=tolower(str1[i].s1[j+m])) { f=0; break; } if(f==1&&((j==0&&(!isalpha(str1[i].s1[j+m])))||(j!=0&&(!isalpha(str1[i].s1[j-1]))&&(!isalpha(str1[i].s1[j+m]))))) { str1[i].sum++;// printf("m1=%c\n",str1[i].s1[j-1]);// printf("m=%c\n",str1[i].s1[j+m]); } } }}int cmp( void const *a, void const *b){ struct node *aa=( node*) a; struct node *bb=( node*) b; if((bb->sum)==(aa->sum)) return (aa->no)-(bb->no); return (bb->sum)-(aa->sum);}int main(){ while(scanf("%d%d",&n,&k)!=EOF) { memset(str1,0,sizeof(str1)); memset(str,0,sizeof(str)); for(int i=0; i<n; i++) { scanf(" %s",str[i]);// for(int j=0;str[i][j]!='\0';j++)// str[i][j]=tolower(str[i][j]); } getchar(); for(int i=0; i<k; i++) { int t=0,l=0; while(1) { char c; c=getchar(); if(c=='\n'||c==EOF) break; str1[i].s1[l++]=c; if(islower(c)) str1[i].s[t++]=c; else if(isupper(c)) str1[i].s[t++]=tolower(c); } str1[i].s[t]='\0'; str1[i].sum=0; str1[i].no=i; str1[i].s1[l]='\0'; pb(i); } qsort(str1,k,sizeof(str1[0]),cmp);// for(int i=0;i<k;i++)// printf("%d ",str1[i].sum); int MAX=str1[0].sum; int t=1; printf("Excuse Set #%d\n",Case); Case++; printf("%s\n",str1[0].s1); while(str1[t].sum==MAX&&t<k) { printf("%s\n",str1[t].s1); t++; } printf("\n"); } return 0;}
0 0
- poj1598(字符串处理)
- 1poj1598(字符串)
- poj1598
- poj1598
- POJ1598
- poj1598 Excuses, Excuses!
- poj1598 Excuses,Excuses!
- POJ1598-C语言
- 成绩处理(字符串)
- (4)字符串处理
- Ural1089(字符串处理)
- Uva227Puzzle(字符串处理)
- 字符串处理(库函数)
- 正确答案(字符串处理)
- Encoding(字符串处理)
- 字符串处理(UVA10082 )
- 03-截取字符串(字符串处理)
- HDOJ 1004 字符串处理(字符串统计)
- Android 学习历程摘要(一)
- 使用socket.io和node.js搭建websocket应用
- FileStream 的FileShare一点小认识
- hdu 4862解题报告
- android学习--视图列表(ListView和ListActivity)
- poj1598(字符串处理)
- 【九度OJ】1029【HashMap查找】
- 每天一个Linux命令
- Code Review(一)
- MySQL索引类型总结和使用技巧以及注意事项
- POJ 1062 昂贵的聘礼
- 封装 ASIHTTPRequest 多请求管理类
- LeetCode | Combination Sum(元素的和)
- Android Activity活动探究