不到20行代码的猜数字游戏,大家评评
程序代码:
#include <iostream> #include <ctime> const char *subter_ = "少了!", *hyper_ = " 高了!", *right = "恭喜你猜对了!"; const char* get_diff(int input, int random){ return (input > random) ? hyper_ : ((input < random) ? subter_ : right); } int judge(int input, int random){ return puts(get_diff(input, random)),(input == random) ? 1 : 0; } int main(void){ srand((unsigned)time(0)); long random = rand() % 1000 + 1, init_money = 0, input = 0, degree = 11; while(degree--) (scanf("%d", &input),(!judge(input, random)))? judge(input, random),printf("你还有%d次机会\n", degree) : 1; return 0; }
[[it] 本帖最后由 蓝一 于 2008-6-3 22:35 编辑 [/it]]