2019 gplt团体程序设计天梯赛总结
分很菜…
以后写题一定记得把题意理清楚了再开始写。
模拟题还是大坑,代码还是写得不够多,代码量一大就写bug。
补题
l1-8 估值一亿的AI核心代码
补题链接:https://pintia.cn/problem-sets/994805046380707840/problems/1111914599412858885
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> #include <string> #include <vector> #include <queue> #include <set> #include <map> #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"; // 7 char couldYou[] = "could you"; // 9 char me[] = "me"; // 2 inline 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<len; i++) if(s[i] != ' ') { tp_begin = i-1; break; } for(int i=len-1; 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<now_cnt;i++) { if(isSepar(s[i])) { printf("%c", s[i]); i = print(i, now_cnt); } else printf("%c", s[i]); } puts(""); } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步