uva 123 - Searching Quickly
来源:互联网 发布:拼接屏调试软件 编辑:程序博客网 时间:2024/04/30 22:18
题意:给几个可以忽略的单词 然后给一些句子 句子中除了忽略的单词都是关键字 对关键字排字典序 对同一个关键字 先输入的先输出 同一个句子中两个关键字相同的关键字在前面的排前面 最后输出的时候除了关键字大写 其余全是小写
下面是代码
#include<cstdio>#include<cstring>#include<cctype>#include<algorithm>using namespace std;int T,cnt;struct STR{ char s[1000]; int n; int l; int visit;}str[205],word[3005],result[3005];int Compare(struct STR a, struct STR b){ if(a.l < b.l)return 1; if(a.l > b.l)return 0; if(a.visit < b.visit)return 1; if(a.visit > b.visit) return 0;}int cmp(struct STR a, struct STR b){ int i; if(strcmp(a.s,b.s) == 0) return Compare(result[a.n],result[b.n]); else { for(i = 0; a.s[i]!='\0'&&b.s[i]!='\0'; i++) { if(a.s[i] < b.s[i])return 1; else if(a.s[i] > b.s[i])return 0; } if(a.s[i] == '\0')return 1; else if(b.s[i] == '\0')return 0; }}int main(){ #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL char s[55][1005]; int n = 0; while(gets(s[n])) { if(strcmp(s[n],"::")==0)break; n++; } while(gets(str[T].s)!=NULL) { for(int j = 0; str[T].s[j]!='\0';j++) if(isalpha(str[T].s[j]))str[T].s[j] = tolower(str[T].s[j]); T++; } for(int i = 0; i < T; i++) { for(int j = 0; str[i].s[j]!='\0'; j++) { if(!isalpha(str[i].s[j]))continue; int t = 0; word[cnt].visit = result[cnt].visit = j; while(isalpha(str[i].s[j]))word[cnt].s[t++] = str[i].s[j++]; word[cnt].s[t] = '\0'; int flag = 1; for(int k = 0; k < n&&flag; k++) if(strcmp(word[cnt].s,s[k]) == 0){flag =0;break;} if(flag) { word[cnt].n = cnt; result[cnt].l = word[cnt].l = i; strcpy(result[cnt].s,str[i].s); for(int x =0 ; word[cnt].s[x]!='\0';x++) { word[cnt].s[x] = toupper(word[cnt].s[x]); result[cnt].s[word[cnt].visit+x] = word[cnt].s[x]; } cnt++; } } } sort(word,word+cnt,cmp); for(int i = 0 ; i < cnt; i++) puts(result[word[i].n].s); return 0;}
- UVa 123 Searching Quickly
- uva 123 Searching Quickly
- UVA 123 - Searching Quickly
- uva 123 - Searching Quickly
- uva-123 - Searching Quickly
- UVA 123 - Searching Quickly
- UVa 123 - Searching Quickly
- UVa 123 Searching Quickly
- uva 123 - Searching Quickly
- uva 123Searching Quickly
- UVA 123 Searching Quickly
- uva 123 - Searching Quickly
- uva - 123 - Searching Quickly
- UVa - 123 - Searching Quickly
- uva 123 Searching Quickly
- uva - 123 - Searching Quickly
- UVa 123 - Searching Quickly
- UVA 123 Searching Quickly
- IAP 计费被拒绝解决方案
- 字符串的分割
- struct和class的异同
- org.xml.sax.SAXException
- php验证码实现及使用--面向过程版
- uva 123 - Searching Quickly
- [ JS ] 某一个月份的若干个月份之后的月份
- HDOJ 4578 线段树
- latex 生成 中文pdf文档
- string类型转换成double-long
- jQuery Custom PopUp Window
- Linux下的tar压缩解压缩命令详解
- jQuery Custom PopUp Window
- HDU 3555 Bomb