uva489

Posted 033000-

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva489相关的知识,希望对你有一定的参考价值。

题意见紫书

代码很久以前写,不太简洁

因此再贴一个刘汝佳代码

#include<iostream>
#include<cstring>
using namespace std;
const int N=26;
int vis[10][N];
bool flag;
bool sum(int *a)
{
    for(int i=0;i<N;i++)
    if(a[i]) return false;
    return true;
}
int main()
{
    int loop,ans=0,cnt;
    string str;
    while(cin>>loop&&loop>0)
    {
        flag=false;
        memset(vis,0,sizeof(vis));
        cin>>str;
        for(int i=0;i<str.length();i++)
        {
            vis[0][str[i]-a]=1;
            vis[1][str[i]-a]=1;
            vis[2][str[i]-a]=1;
        }
        cin.clear();
        cin>>str;
        cnt=0;
        
        for(int i=0;i<str.length();i++)
        {
            if(vis[1][str[i]-a]) vis[1][str[i]-a]=0;
            if(vis[2][str[i]-a]==0) cnt++,vis[2][str[i]-a]=1;
            if(cnt==7) {
                cout<<"Round "<<loop<<endl;
                cout<<"You lose."<<endl;
                flag=1;break;
            }
            if(sum(vis[1])) {
                cout<<"Round "<<loop<<endl;
                cout<<"You win."<<endl;
                flag=1;break;
            }
        }
        if(!flag)
        {
            cout<<"Round "<<loop<<endl;
            cout<<"You chickened out."<<endl;
        }
    }
}

刘汝佳

// UVa489 Hangman Judge
// Rujia Liu
#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;
}

 

以上是关于uva489的主要内容,如果未能解决你的问题,请参考以下文章

UVa 489 HangmanJudge --- 水题

uva 489 Hangman Judge

UVa 489:Hangman Judge

UVA-489 Hangman Judge

UVA 489-- Hangman Judge(暴力串处理)

紫书uva489·坑OJ