URAL 1089|Verification with a Vocabulary|暴力
来源:互联网 发布:自动注音软件 编辑:程序博客网 时间:2024/06/11 11:38
http://acm.timus.ru/problem.aspx?space=1&num=1089
题目
你的英语老师跟你说她最近梦想有一个自动化的系统去批改小学生的作业,并统计有多少个单词拼错了。3月8号就要到了,你想写一个程序实现老师的想法,当做礼物送给老师,这样老师在考试打分的时候就可以照顾一下你。程序需要实现:替换错误的单词(正确的单词拼写列表已给出,单词拼写错误不超过一个字母),统计拼错的单词数。你的英语老师忘了小学生还可能漏字母或多一个字母,但是你的程序不用考虑这些,因为老师忘记提这个要求了。
输入
输入文件由2部分组成,第一部分每行一个单词表示单词表内的正确单词(每个单词不超过8个字母),第二部分许多行表示一个小学生写的几个句子(整个文本不超过1000个单词),所有单词都只包含小写字母。不会出现在单词表内找不到对应单词、或者存在2种或以上正确单词对应的情况。
输出
输出修正的正确文本,并输出一行一个整数表示更正单词的个数。
样例输入
countryoccupiessurfacecoversrussialargesteuropepartaboutworld#the rushia is the larjest cauntry in the vorld.it ockupies abaut 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 <vector>#include <string>#define rep(i,j,k) for(i=j;i<k;++i)using namespace std;inline void nextAlphabet(const string &str, int &i) { while (i < str.length() && (str[i] < 'a' || str[i] > 'z')) ++i;}// returns the end index of current word, excluded.inline int skimWord(const string &str, int from) { while (from < str.length() && str[from] >= 'a' && str[from] <= 'z') ++from; return from;}int main() { vector<string> vocabulary; // read vocabulary. string line; while (true) { getline(cin, line); if (line == "#") break; else vocabulary.push_back(line); } // read text, since lines can be merged. string text = ""; int ans = 0, i = 0, j, k; while (getline(cin, line)) text += line + '\n'; // for each words in the text, check the minimum distance to a word in vocabulary and correct them. while (true) { nextAlphabet(text, i); // no more words if (i >= text.length()) break; int to = skimWord(text, i); string word = text.substr(i, to - i); // search the vocabulary rep(j,0,vocabulary.size()) { string correct = vocabulary[j]; if (correct.length() == word.length()) { int d = -1; rep(k,0,word.length()) if (vocabulary[j][k] != word[k]) { if (d == -1) d = k; else { d = -1; break; } } if (d != -1) { ++ans; text[i + d] = correct[d]; break; } } } i = to; } cout << text << ans << endl; return 0;}
阅读全文
0 0
- URAL 1089|Verification with a Vocabulary|暴力
- Scalable Recognition with a Vocabulary Tree
- [论文阅读]词汇树 Scalable Recognition with a Vocabulary Tree
- vocabulary
- Vocabulary
- vocabulary
- Vocabulary
- Vocabulary
- vocabulary
- vocabulary
- Vocabulary
- Vocabulary
- URAL 1011|Conductors|暴力
- URAL 1083|Factorials!!!|暴力
- Aspect-Oriented Programming with the e Verification Language: A Pragmatic Guide for Testbench Develo
- Codeforces 729A Interview with Oleg 简单暴力
- English Vocabulary in Use Elementary, with Answers by Michael McCarthy
- Dalvik Optimization and Verification With dexopt
- Java中运算符的优先级
- c python shell文件读写
- shell编程向函数传递数组
- SSM框架入门和搭建
- Cookie/Session机制详解
- URAL 1089|Verification with a Vocabulary|暴力
- 数据库建立远程链接的方法
- qbxt Day 6 搜索+乱搞+差分约束
- Spring面向切面编程——什么是面向切面编程
- 《着色器和屏幕特效》读书笔记第八章-用Unity的渲染纹理实现屏幕特效
- lua_func.hpp
- sort总结
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 GSM Base Station Identification 线性变换||计算几何
- 第一次写博客