UVA489查找到的字符可以变成不可能会查找到的

来源:互联网 发布:faceu软件 编辑:程序博客网 时间:2024/05/29 08:21

这题注意已经猜测成功的字母,再次猜测是按照错的处理,另外对于同一个字母猜错俩次是按照俩次算的,被提议误导了,加了一个flag2数组,然而并不需要

,另外这题为了判断已经猜对的题目再次猜是错的,可以把猜对的字母变成字母外的可打印字符,例如*,这样还可以去掉flag数组。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<cctype>using namespace std;int main(){    int r;    while(cin>>r&&r!=-1)    {        string s1,s2;        cin>>s1;        cin>>s2;        int flag[1005];        int flag2[100];        memset(flag,0,sizeof(flag));        memset(flag2,0,sizeof(flag2));        int len=0;        int f=0;        for(int i=0;i<s2.length();i++)        {            int tem=0;            for(int j=0;j<s1.length();j++)            {                if(s2[i]==s1[j]&&!flag[j])                {                    len++;                    flag[j]=1;                    tem=1;                }            }            if(!tem&&!flag2[s2[i]-'a'])              {                  flag2[s2[i]-'a']=1;                  f++;              }            if(len==s1.length()||f==7)                break;        }        if(f==7)            cout<<"Round "<<r<<endl<<"You lose."<<endl;        else if(len==s1.length())            cout<<"Round "<<r<<endl<<"You win."<<endl;        else            cout<<"Round "<<r<<endl<<"You chickened out."<<endl;    }    return 0;}


0 0
原创粉丝点击