poj 1035 纯正的字符串水

Spell checker

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 22673   Accepted: 8258

Description

You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given words using a known dictionary of all correct words in all their forms. If the word is absent in the dictionary then it can be replaced by correct words (from the dictionary) that can be obtained by one of the following operations:
?deleting of one letter from the word; ?replacing of one letter in the word with an arbitrary letter; ?inserting of one arbitrary letter into the word. Your task is to write the program that will find all possible replacements from the dictionary for every given word.

Input

The first part of the input file contains all words from the dictionary. Each word occupies its own line. This part is finished by the single character ‘#‘ on a separate line. All words are different. There will be at most 10000 words in the dictionary. The next part of the file contains all words that are to be checked. Each word occupies its own line. This part is also finished by the single character ‘#‘ on a separate line. There will be at most 50 words that are to be checked. All words in the input file (words from the dictionary and words to be checked) consist only of small alphabetic characters and each one contains 15 characters at most.

Output

Write to the output file exactly one line for every checked word in the order of their appearance in the second part of the input file. If the word is correct (i.e. it exists in the dictionary) write the message: " is correct". If the word is not correct then write this word first, then write the character ‘:‘ (colon), and after a single space write all its possible replacements, separated by spaces. The replacements should be written in the order of their appearance in the dictionary (in the first part of the input file). If there are no replacements for this word then the line feed should immediately follow the colon.

Sample Input

i
is
has
have
be
my
more
contest
me
too
if
award
#
me
aware
m
contest
hav
oo
or
i
fi
mre
#

Sample Output

me is correct
aware: award
m: i my me
contest is correct
hav: has have
oo: too
or:
i is correct
fi: i
mre: more me
#include<stdio.h>
#include<string.h>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
string s;
int main(){
    vector<string>q;
    while(cin>>s){
        if(s=="#")
            break;
        q.push_back(s);

    }
    while(cin>>s){
            if(s=="#")
            break;
      int len=s.size();
      bool flag=false;
     cout<<s;
      for(int i=0;i<q.size();i++){
        if(s==q[i]){
            flag=true;
            cout<<" is correct"<<endl;
    break;
        }
      }

      if(!flag){
            cout<<":";
          for(int i=0;i<q.size();i++){
            int len1=q[i].size();
            int temp=len1-len;
            if(temp>1||temp<-1)
                continue;
            int d=0;
            if(temp==0){
                for(int j=0;j<len;j++){
                    if(s[j]!=q[i][j])
                        d++;
                }
                if(d==1)
                    cout<<‘ ‘<<q[i];
            }

            else if(temp==-1){
                for(int j=0;j<len;j++){
                    if(s[j]==q[i][d]){
                        d++;
                    }
                }
                if(d==len1)
                    cout<<‘ ‘<<q[i];
            }

            else if(temp==1){
                for(int j=0;j<len1;j++){
                    if(s[d]==q[i][j]){
                        d++;
                    }
                }
                if(d==len)
                    cout<<‘ ‘<<q[i];
            }

          }
  cout<<endl;
      }

    }
    return 0;
}
时间: 2024-10-07 06:13:45

poj 1035 纯正的字符串水的相关文章

POJ 1035 Spell Check 字符串处理

被这样的题目忽悠了,一开始以为使用Trie会大大加速程序的,没想到,一不小心居然使用Trie会超时. 最后反复试验,加点优化,终于使用Trie是可以过的,不过时间大概难高于1500ms,一不小心就会超时. 看来这是一道专门卡Trie的题目,只好放弃不使用Trie了. 也得出点经验,如果字符串很多,如本题有1万个字符串的,那么还是不要使用Trie吧,否则遍历一次这样的Trie是十分耗时的,2s以上. 于是使用暴力搜索法了,这里的技巧是可以使用优化技术: 1 剪枝:这里直接分组搜索,分组是按照字符串

POJ 1035 代码+详细注释

Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19319 Accepted: 7060 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given words us

POJ 1035 代码+具体的目光

Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19319 Accepted: 7060 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given words us

1001 字符串“水”题

1001: 字符串“水”题 时间限制: 1 Sec  内存限制: 128 MB提交: 210  解决: 39[提交][状态][讨论版] 题目描述 给出一个长度为 n 的字符串(1<=n<=100000),求有多少个连续字串中所有的字母都出现了偶数次. 输入 第一行一个正整数 T,表示数据组数(1 <= T <= 10). 接下来 T 行,每行有一个只包含小写字母的字符串. 输出 每个答案输出满足要求字符串个数.每个答案占一行. 样例输入 3 a aabbcc abcabc 样例输出

[ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given word

poj 1579 Moving Tables(水)

Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, a m = a m−1 − m if the rsulting a m is positive and not already in the sequence, otherwise a m = am−1 + m. The first few numbers in the Recaman's Sequence is 0, 1, 3, 6, 2, 7, 13, 2

poj 3031 Big Christmas Tree(水spfa)

http://poj.org/problem?id=3013 题意: Because of a technical difficulty, price of an edge will be (sum of weights of all descendant nodes) × (unit price of the edge).这句话一直没看懂.后面还以为是最小生成树. 正确题意是:给一个无向图,计算每个点到1节点的最短路径(dis[i]) * 每个节点的weights之和. 注意:边权值等要用__

POJ 1274 The Perfect Stall 水二分匹配

题目链接:点击打开链接 嘿嘿 #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<vector> #include<queue> #include<functional> #define N 2011 using namespace std; int lef[N], pn;//lef[v]表示Y集的点v 当前连接

HDU4891_The Great Pan_字符串水题

2014多校第五题,当时题面上的10^5写成105,我们大家都wa了几发,改正后我和一血就差几秒…不能忍 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4891 The Great Pan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 966    Accepted Submission(s