#define _CRT_SECURE_NO_DEPRECATE; #define _CRT_SECURE_NO_WARNINGS; #define gets gets_s #pragma warning(disable:4996); #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int main() { int num = 0;//记录Case数目 int T;//T组测试数据 scanf("%d", &T); while (T--) { int hp = 30;//初始生命值 int def = 0;//防御值 int len;//冒险长度 int flag = 0;//记录力量神符 char adv[105];//存储冒险内容 int i = 0; num++; scanf("%s", adv); len = strlen(adv); for (i = 0; i < len; i++) { if (hp <= 0)//血量为0直接跳出 { break; } if (adv[i] == 'E')//到达终点直接跳出 { break; } else if (adv[i] == '#')//掉入落穴陷阱,主人公HP-3 { if (flag)//如果此时有力量神符,则不会扣血,下同 { flag--; continue; } else if (def >= 3)//如果防御值高过3,则不会扣血,下同 continue; else hp = hp + def - 3; } else if (adv[i] == 'I')//清理路障,主人公HP-1 { if (flag) { flag--; continue; } else if (def >= 1) continue; else hp = hp - 1; } else if (adv[i] == 'G')//打倒哥布林,主人公HP-5 { if (flag) { flag--; continue; } else if (def >= 5) continue; else hp = hp + def - 5; } else if (adv[i] == 'B')//挑战BOSS,主人公HP-20 { if (flag) { flag--; continue; } else if (def >= 20) continue; else hp = hp + def - 20; } else if (adv[i] == 'S')//与史莱姆缠斗,主人公HP-2 { if (flag) { flag--; continue; } else if (def >= 2) continue; else hp = hp + def - 2; } else if (adv[i] == 'H')//拾取治疗神符,主人公HP+15 { hp = hp + 15; if (hp > 30) hp = 30; } else if (adv[i] == 'P')//拾取力量神符,主人公在接下来的5步内HP不会减少(不包含当前步) { flag = 5; } else if (adv[i] == 'A')//拾取防具,主人公在接下来所有的旅程中受到伤害减少1点(例:通过第一个A点后,此时遭遇哥布林,HP - 4) { def++; } else//平静的道路,什么也不会发生 { continue; } } if (hp <= 0) printf("Case #%d:0\n", num); else printf("Case #%d:%d\n", num, hp); } return 0; } /* Main.cc:1:33: warning: ISO C99 requires whitespace after the macro name #define _CRT_SECURE_NO_DEPRECATE; ^ Main.cc:2:32: warning: ISO C99 requires whitespace after the macro name #define _CRT_SECURE_NO_WARNINGS; ^ Main.cc:4:0: warning: ignoring #pragma warning [-Wunknown-pragmas] #pragma warning(disable:4996); ^ In file included from /usr/include/c++/4.9/ext/string_conversions.h:43:0, from /usr/include/c++/4.9/bits/basic_string.h:2850, from /usr/include/c++/4.9/string:52, from /usr/include/c++/4.9/random:40, from /usr/include/c++/4.9/bits/stl_algo.h:66, from /usr/include/c++/4.9/algorithm:62, from Main.cc:8: /usr/include/c++/4.9/cstdio:124:11: error: '::gets' has not been declared using ::gets; ^ */ |
Double click to view unformatted code.