Ural1089(字符串处理)
来源:互联网 发布:年会礼品 知乎 编辑:程序博客网 时间:2024/06/05 11:12
1089. Verification with a Vocabulary
Time limit: 2.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Your teacher of English has recently told you that she dreams about the automated system of correction and count of mistakes that her pupils do very frequently.The 8th of March is soon and you've decided that if you write such program and you'll present your teacher with it, then she will be glad and may be will be more favorable to you at the exam. The task is to replace words that differ from the ones in the vocabulary not more than by a letter and to count an amount of the made mistakes. Your teacher must have forgotten that her pupils sometimes forget to write letters and even sometimes they write extra letters - excellent! You are not to think about it!
Input
In the first line and then up to the line containing the only symbol `#' go vocabulary words, each word in its line. In the lines that go after the one containing `#' goers a text that you are to check-up. There are not more than 100 words in the vocabulary. A length of a word in the vocabulary doesn't exceed 8 symbols. A length of the text being checked-up doesn't exceed 1000 words. All the words are written in the lower case. A word might contain Latin letters from `a' to `z'. The vocabulary is compiled so that for each word not more than one variant of correction is possible. There's exactly one end of line character at the end of the text.
Output
You are to output the corrected text in the same format as the initial one (the same punctuation marks, line breaks and words that are absent in the vocabulary) and in the line next to the text there is to be a number of corrections.
Sample
countryoccupiessurfacecoversrussialargesteuropepartaboutworld#the rushia is the larjest cauntry in the vorld.it ockupies ebout one-seventh of the earth's surfase.it kovers the eastern park of yurope and the northern park of asia.
the russia is the largest country in the world.it occupies about one-seventh of the earth's surface.it covers the eastern part of europe and the northern part of asia.11题意:就是改正字典中存在的,文件中写错一个字符的单词,然后输出。
做的过程中的难点就是想不到如何从字符串中提取单词,如何读入文件?当然这个题给了我很大的启发,可以单个字符处理。
其实这种做法,上一道题也有类似的做法,自己没想到。。
总之还是有收获的,不要纠结于暂时的得与失。
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;char doc[3005][15];bool check(char a[],char b[]){int len=strlen(a),len1=strlen(b),count=0;if(len!=len1)return false;for(int i=0;i<len;i++){if(a[i]!=b[i])count++;}if(count==1)return true;else return false;}int main(){//freopen("q.in","r",stdin);int i,j;int total=0;char s[15]; //因为文件里的单词可能超过10,而文件里的单词也是暂存在这里的,所以数组要开的大些。开小了WA。。。。 char ch;int res=0,cnt;while(~scanf("%s",s) && s[0]!='#')strcpy(doc[total++],s);getchar();cnt=0;memset(s,0,sizeof(s)); //存单词 while(~scanf("%c",&ch)){if(!isalpha(ch)){ bool flag=false;for(i=0;i<total;i++){if(check(s,doc[i])){res++;cout<<doc[i];flag=true;break;}}if(!flag){cout<<s;}cout<<ch;memset(s,0,sizeof(s));cnt=0;}else{s[cnt++]=ch;} }cout<<endl;cout<<res<<endl;}
0 0
- Ural1089(字符串处理)
- 成绩处理(字符串)
- (4)字符串处理
- poj1598(字符串处理)
- Uva227Puzzle(字符串处理)
- 字符串处理(库函数)
- 正确答案(字符串处理)
- Encoding(字符串处理)
- 字符串处理(UVA10082 )
- 03-截取字符串(字符串处理)
- HDOJ 1004 字符串处理(字符串统计)
- 字符串划分(DP+字符串处理)
- 字符串处理(5)字符串数组
- 字符串处理(7)字符串标记
- php字符串处理(邮件处理)
- PHP字符串处理(一)
- PHP字符串处理(二)
- StringTokenizer类(字符串处理)
- 使用 OpenSSL API 进行安全编程
- 动态加载 python 文件
- CODEVS-1531 山峰
- 王帅:深入PHP内核(二)——SAPI探究
- MVC模型
- Ural1089(字符串处理)
- Unity3D里面的JavaScript和浏览器的JavaScript的大致区别
- 普通模糊,动感模糊,高斯模糊算法实现
- PHP相关系列 - 优化你的PHP代码
- 用Bundle和直接用Intent.putExtra("xx",yy)传递有什么不同
- 使用 OpenSSL API 进行安全编程,第 2 部分: 安全握手
- ios&java 常用加密(二)单向加密
- "The Civil War in France" translation05
- Java语言基本语法