本文主要是介绍例题4-2 刽子手游戏(Hangman Judge,UVa 489),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原题链接:https://vjudge.net/problem/UVA-489
分类:函数
备注:水题
前言:只要好好理解了题目意思就OK了,深感做题理解题意的重要性,好好学英语啊!
代码如下:
#include<stdio.h>
#include<string.h>
void solve(char* s1, char* s2)
{int left = 7, len1 = strlen(s1), len2 = strlen(s2);for (int i = 0; i < len2; i++){int get = 0, win = 1;for (int j = 0; j < len1; j++){if (s1[j] == s2[i]) { get = 1; s1[j] = '-'; }//猜对的字符变成'-'if (s1[j] != '-')win = 0;}if (win) { printf("You win.\n"); return; }if (!get)left--;if (!left) { printf("You lose.\n"); return; }}printf("You chickened out.\n");
}
int main(void)
{int kase;char s1[10000], s2[10000];while (~scanf("%d", &kase) && kase != -1){scanf("%s%s", s1, s2);printf("Round %d\n", kase);solve(s1, s2);}return 0;
}
这篇关于例题4-2 刽子手游戏(Hangman Judge,UVa 489)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!