zoukankan      html  css  js  c++  java
  • UVA489

    题意:就是给出一个字符串,让你去一个一个猜测,相同字母算一次,如果是之前猜过的也算错,如果你在错7次前猜对就算你赢,文章中是LRJ的例题代码。

    #include<stdio.h>
    #include<string.h>
    #define maxn 100
    int left, chance;
    char s[maxn], s2[maxn];
    int win, lose;
    
    void guess(char ch) {
      int bad = 1;
      for(int i = 0; i < strlen(s); i++)
        if(s[i] == ch) { left--; s[i] = ' '; bad = 0; }
      if(bad) --chance;
      if(!chance) lose = 1;
      if(!left) win = 1;
    }
    
    int main() {
      int rnd;
      while(scanf("%d%s%s", &rnd, s, s2) == 3 && rnd != -1) {
        printf("Round %d
    ", rnd);
        win = lose = 0;
        left = strlen(s);
        chance = 7;
        for(int i = 0; i < strlen(s2); i++) {
          guess(s2[i]);
          if(win || lose) break;
        }
        if(win) printf("You win.
    ");
        else if(lose) printf("You lose.
    ");
        else printf("You chickened out.
    ");
      }
      return 0;
    }
    #include<cstdio>
    #include<cstring>
    #include <iostream>
    using namespace std;
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF && n!=-1)
        {
            char str1[1005],str2[1005];
            int a[27],b[27];
            printf("Round %d
    ",n);
            scanf("%s%s",str1,str2);
            int len1=strlen(str1);
            int len2=strlen(str2);
            memset(a,0,sizeof(a));
            memset(b,1,sizeof(b));
            int x=0,y=0,z=0,t=0;
            for(int i=0;i<len1;++i)
            {
                a[str1[i]-'a']=1;
            }
            for(int i=0;i<len1;++i)
            {
                if(a[str1[i]-'a']==1 && b[str1[i]-'a'])
                {
                    t++;
                    b[str1[i]-'a']=0;
                }
            }
            for(int i=0;i<len2;++i)
            {
                if(a[str2[i]-'a']==1)
                {
                    x++;
                    a[str2[i]-'a']=-1;
                }
                else if(a[str2[i]-'a']==0)
                    y++;
                else
                    z++;
                if(y>6 || x-z>=t)
                    break;
            }
            if(y>6)
                printf("You lose.
    ");
            else if(x-z>=t)
                printf("You win.
    ");
            else
                printf("You chickened out.
    ");
        }
        return 0;
    }
  • 相关阅读:
    pkuwc2019自闭记
    一些多项式的整理
    Codeforces 1085G(1086E) Beautiful Matrix $dp$+树状数组
    Codeforces 1083C Max Mex 线段树
    Codeforces 1090J $kmp+hash+$二分
    Codeforces 1073G Yet Another LCP Problem $SA$+单调栈
    Codedforces 1076G Array Game 线段树
    LuoguP5017 摆渡车 $dp$
    NOIP2018游记
    解决python3 安装turtle的问题
  • 原文地址:https://www.cnblogs.com/aerer/p/9930967.html
Copyright © 2011-2022 走看看