本文共 2450 字,大约阅读时间需要 8 分钟。
分很菜…
以后写题一定记得把题意理清楚了再开始写。
模拟题还是大坑,代码还是写得不够多,代码量一大就写bug。
补题
l1-8 估值一亿的AI核心代码
补题链接:
#include #include #include #include #include #include #include #include #include #include #include #define INF 0x3f3f3f3f#define ll long long#define lowbit(x) (x&(-x))#define PI acos(-1)#define ms(x,y) memset(x, y, sizeof(x))using namespace std;const int maxn = 1e4+7;char s[maxn];char punc[] = "`~!@#$%^&*()_+-={}|[]\\;':\",./<>?";char canYou[] = "can you"; // 7char couldYou[] = "could you"; // 9char me[] = "me"; // 2inline bool isPunc(char c) { for(int i=0;punc[i]!='\0';i++) if(c == punc[i]) return true; return false; }inline bool isCapit(char c) { return c >= 'A' && c <= 'Z'; }inline bool isSepar(char c) { return (c == ' ') | isPunc(c); }inline bool isCanYou(int ptr, int lim){ for(int i=0;canYou[i] != '\0'; i++) { if(i+ptr >= lim) return false; if(s[i+ptr] != canYou[i]) return false; } return 7+ptr >= lim || isSepar(s[7+ptr]);}inline bool isCouldYou(int ptr, int lim){ for(int i=0;couldYou[i] != '\0'; i++) { if(i+ptr >= lim) return false; if(s[i+ptr] != couldYou[i]) return false; } return 9+ptr >= lim || isSepar(s[9+ptr]);}inline bool isMe(int ptr, int lim){ for(int i=0;me[i] != '\0'; i++) { if(i+ptr >= lim) return false; if(s[i+ptr] != me[i]) return false; } return 2+ptr >= lim || isSepar(s[2+ptr]);}int print(int i, int lim){ if(isCanYou(i+1, lim)) { printf("I can"); i += 7; } else if(isCouldYou(i+1, lim)) { printf("I could"); i += 9; } else if(isMe(i+1, lim)) { printf("you"); i += 2; } else if(i+1 < lim && s[i+1] == 'I' && (i+2 >= lim || isSepar(s[i+2]))) { printf("you"); i += 1; } return i;}int main(){ int T; scanf("%d", &T); getchar(); while(T--) { cin.getline(s, maxn); puts(s); int len = strlen(s); int tp_begin = -1, tp_end = 0; int now_cnt = 0; for(int i=0; i =0; i--) if(s[i] != ' ') { tp_end = i; break; } for(int i=tp_begin+1; i<=tp_end; i++) { if(s[i] == ' ') { int j = i+1; while(j <= tp_end && s[j] == ' ') j ++; // i+1~j-1: redundant space if(!isPunc(s[j])) s[now_cnt++] = s[i]; i = j-1; } else { if(isCapit(s[i]) && s[i] != 'I') s[i] = s[i] - 'A' + 'a'; else if(s[i] == '?') s[i] = '!'; s[now_cnt ++] = s[i]; } } s[now_cnt] = '\0'; printf("AI: "); int i = 0; while(i < now_cnt && s[i] == ' ') i ++; // first un-space i = print(i-1, now_cnt); for(i=i+1;i
转载于:https://www.cnblogs.com/HazelNut/p/10634245.html