2018-03-14 Problem Solving►UVa UVa 10530 - Guessing Game Contents 1. Problem2. Solution3. Code Problem題目網址中文網址 Solution一直紀錄上下界,不斷縮小範圍。最後看答案有沒有在內即可。 CodeUVa 10530123456789101112131415161718192021222324252627282930#include <cstdio>int main(){ int up = 11, low = 0, n; char str[20]; bool ok = true; while (scanf("%d ", &n) && n) { fgets(str, 20, stdin); if (str[4] == 'l' && n > low) low = n; else if (str[4] == 'h' && n < up) up = n; else if (str[0] == 'r') { if (n >= up || n <= low) //不在範圍內 ok = false; puts(ok ? "Stan may be honest" : "Stan is dishonest"); ok = true; up = 11; low = 0; continue; } } return 0;} Newer UVa 11506 - Angry Programmer Older UVa 440 - Eeny Meeny Moo