489 Hangman Judge

Problem Link: 489 – Hangman Judge

 

 

#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{

	int n;

	char a[1000],b[1000],c[1000],d[1000];

	while(true){
		cin >> n;
		cin.ignore();

		if(n==-1)
			break;

		cin >> a >> b;

		int e,p=0,q,r;

		for(int i=0;a[i]!='\0';i++){
			e=0;
			for(int j=0;j<i;j++){
				if(a[i]==a[j]){
					e=1;
					break;
					}
				}
			if(e==0)
				c[p++]=a[i];
			}
			c[p]='\0';

			p=0;
		for(int i=0;b[i]!='\0';i++){
			e=0;
			for(int j=0;j<i;j++){
				if(b[i]==b[j]){
					e=1;
					break;
					}
				}
			if(e==0)
				d[p++]=b[i];
			}
			d[p]='\0';

		printf("Round %d\n",n);

			int l=strlen(c);

			p=0,q=0,r=0;
			for(int i=0;d[i]!='\0';i++){
				e=0;
				for(int j=0;c[j]!='\0';j++){
					if(d[i]==c[j]){
						e=1;
						break;
						}
					}
				if(e==0)
					p++;
				else
					q++;

				if(q==l)
					break;

				}

			if(p<7 && q==l)
				printf("You win.\n");
			else if(p>=7)
				printf("You lose.\n");
			else
				printf("You chickened out.\n");

	}

	return 0;}

Advertisements