-
Notifications
You must be signed in to change notification settings - Fork 34
/
10530.cpp
executable file
·56 lines (48 loc) · 1.08 KB
/
10530.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Problem: Guessing Game UVa 10530
Programmer: Md. Mahmud Ahsan
Compiled: Visual C++ 6.0
Date: 09-10-04
*/
#include <iostream>
#include <string>
using namespace std;
int main(){
int array[11];
int guess;
char strA[30];
char strB[30];
int i;
bool flag = true;
// when need a integer input and a string input line by line
// then it's better to use two getline()
while(cin.getline(strA, sizeof(strA))){
if (strlen(strA) == 2)
guess = 10;
else
guess = strA[0] - 48;
if (guess == 0)
break;
cin.getline(strB, sizeof(strB)); // input second line
if (flag){
for (i = 1; i <= 10; i++)
array[i] = 1;
flag = false;
}
if (strcmp(strB, "too high") == 0){
for (i = guess; i <= 10; ++i)
array[i] = 0;
}
else if (strcmp(strB, "too low") == 0){
for (i = guess; i >= 1; --i)
array[i] = 0;
}
else if (strcmp(strB, "right on") == 0){
flag = true;
if (array[guess] == 1)
cout << "Stan may be honest" << endl;
else
cout << "Stan is dishonest" << endl;
}
}
return 0;
}