Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) C

来源:互联网 发布:高晓松酒驾事件知乎 编辑:程序博客网 时间:2024/05/29 03:59

如果在!中没有出现过,那么这些字母没有嫌疑,如果在?或.中出现过,那么这些字母没有嫌疑。当最后只剩一个字母有嫌疑时,就确定了假设的字母,这时候我们只需要判别之后出现的?和!的数目即可。

#include <iostream>#include <string>using namespace std;bool notis[30]={false},mayis[30]={false};string str;int main(){    int n,flag=0,cnt=0,tem,i,j;char p;    std::ios::sync_with_stdio(false);    cin>>n;    for(i=0;i<n;i++){        cin>>p>>str;        if(flag&&(p=='!'||p=='?'))cnt++;        else{            tem=str.length();            if(p=='!'){                for(j=0;j<tem;j++)mayis[str[j]-'a']=true;                for(j=0;j<26;j++){                    if(!mayis[j])notis[j]=true;                    mayis[j]=false;                }            }else for(j=0;j<tem;j++)notis[str[j]-'a']=true;            for(tem=j=0;j<26;j++)if(!notis[j])tem++;            if(tem==1)flag=1;        }    }    printf("%d",cnt>0?(cnt-1):0);}
阅读全文
0 0