PC110304/UVA850

来源:互联网 发布:ps软件源码下载 编辑:程序博客网 时间:2024/06/05 03:00

这题目WA了好几次,主要是我没有理解清楚No solution.这个情况。

如果在match原文做好了,基本map一下就能过了。

与原句match的条件就是:

1.出现了26个字母

2.该空格的地方要空格,不该空格的地方不要空格

3.该相同的地方相同,不该相同的地方不相同。

~真的是好久不做PC题目,输入输出都不习惯了~弄得好郁闷。

/*******************************************************************************//* OS           : 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 UTC 2013 GNU/Linux * Compiler     : g++ (GCC)  4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) * Encoding     : UTF8 * Date         : 2014-03-30 * All Rights Reserved by yaolong.*****************************************************************************//* Description: ********************************************************************************************************************************************//* Analysis: ***********************************************************************************************************************************************//*****************************************************************************/#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<vector>using namespace std;string KN="the quick brown fox jumps over the lazy dog";int lenKN=KN.length();char p[27];bool isMatch(string s){    int i,j;    if(s[3]!=' '||s[9]!=' '||s[15]!=' '||s[ 19]!=' '||s[25]!=' '|| s[30]!=' '||s[34]!=' '||s[39]!=' ')       return 0;    memset(p,0,sizeof(27));    for(i=0;i<s.length();i++){       if(s[i]!=' ')       p[s[i]-'a']++;    }    int res=0;    for(i=0;i<26;i++){       if(p[i]) res++;    }    if(res!=26) return 0;    for(i=0;i<lenKN;i++){       for(j=0;j<lenKN;j++){          if(KN[i]==KN[j]&&s[i]!=s[j]){            return 0;          }          if(KN[i]!=KN[j]&&s[i]==s[j]){            return 0;          }       }    }    return 1;}int main(){    int cases,i,j;    vector<string> str;    string tmp;    map<char,char> mp;    cin>>cases;    getchar();    getchar();    int first=1;    while(cases--)    {        if(first) first=0;        else cout<<endl;        mp.clear();        str.clear();        while(getline(cin,tmp)&&tmp.length())        {            str.push_back(tmp);        }        int siz=str.size();        int flag=0;        for(i=0; i<siz; i++)        {            if(str[i].length()==lenKN&&isMatch(str[i]))            {                flag=1;                for(j=0; j<lenKN; j++)                {                    mp[str[i][j]]=KN[j];                }            }        }        if(flag)        {            for(i=0; i<siz; i++)            {                for(j=0; j<str[i].length(); j++)                    cout<<mp[str[i][j]];                cout<<endl;            }        }        else cout<<"No solution.\n";    }    return 0;}


0 0
原创粉丝点击