zoukankan      html  css  js  c++  java
  • uva489(需要考虑周全)

    这个题是简单题,但是我的思路本身不周全,忽略了一种比较“无理”的情况,而导致WA多次。我是把猜的串全扫一遍以后判断出结果,但是实际上可能是前面已经全猜对了,但是这个选手是个逗比,已经猜对了还要猜,而且后面还又猜错了几次,导致最后猜错的总次数大于7。这种情况下应该也算win的。所以如果已经全猜对了,就跳出,不要再看g串后面的了。这种不太正常的输入也是符合题目要求的,不能不考虑。以后要注意这些陷阱。

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #include<ctype.h>
    using namespace std;
    #define INF 1000000000
    #define eps 1e-8
    #define pii pair<int,int>
    #define LL long long int
    #define maxn 110
    int cas,ans,a[26],chu;
    char anstr[3][30]= {{"You win."},{"You lose."},{"You chickened out."}};
    char y[100000],g[100000];
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        while(scanf("%d",&cas)==1)
        {
            if(cas==-1) break;
            ans=0;
            chu=0;
            memset(a,0,sizeof(a));
            scanf("%s%s",y,g);
            int leny=strlen(y);
            int leng=strlen(g);
            for(int i=0; i<leny; i++)
            {
                a[y[i]-'a']++;
            }
            int cuo=0;
            for(int i=0; i<leng; i++)
            {
                if(chu==leny) {break;}
                if(a[g[i]-'a']==0)
                {
                    cuo++;
                    a[g[i]-'a']=-1;
                    if(cuo==7)
                    {
                        ans=1;
                        break;
                    }
                }
                else if(a[g[i]-'a']>0)
                {
                    chu+=a[g[i]-'a'];
                    a[g[i]-'a']=0;
                }
            }
            if((cuo<7)&&(chu<leny))
            {
                for(int i=0; i<26; i++)
                {
                    if(a[i]>0)
                    {
                        ans=2;
                        break;
                    }
                }
            }
            printf("Round %d
    ",cas);
            printf("%s
    ",anstr[ans]);
        }
        //fclose(stdin);
        //fclose(stdout);
        return 0;
    }
  • 相关阅读:
    phpStudy mysql升级至5.7
    apache 子域名自动与子域名同名的目录绑定
    js 移动端获取当前用户的经纬度
    PHPStudy环境下搭建composer
    MySQL sock 文件丢失被删除解决方法
    Nginx+Php-fpm运行原理详解
    服务器反爬虫攻略:Apache/Nginx/PHP禁止某些User Agent抓取网站
    php 下载文件/直接下载数据内容
    window 克隆复制当前窗口
    staff
  • 原文地址:https://www.cnblogs.com/zywscq/p/3978939.html
Copyright © 2011-2022 走看看