2019 gplt团体程序设计天梯赛总结
2024-08-31 04:40:47
分很菜…
以后写题一定记得把题意理清楚了再开始写。
模拟题还是大坑,代码还是写得不够多,代码量一大就写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+;
char s[maxn];
char punc[] = "`~!@#$%^&*()_+-={}|[]\\;':\",./<>?";
char canYou[] = "can you"; //
char couldYou[] = "could you"; //
char me[] = "me"; // inline bool isPunc(char c) { for(int i=;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=;canYou[i] != '\0'; i++)
{
if(i+ptr >= lim) return false;
if(s[i+ptr] != canYou[i]) return false;
}
return +ptr >= lim || isSepar(s[+ptr]);
}
inline bool isCouldYou(int ptr, int lim)
{
for(int i=;couldYou[i] != '\0'; i++)
{
if(i+ptr >= lim) return false;
if(s[i+ptr] != couldYou[i]) return false;
}
return +ptr >= lim || isSepar(s[+ptr]);
}
inline bool isMe(int ptr, int lim)
{
for(int i=;me[i] != '\0'; i++)
{
if(i+ptr >= lim) return false;
if(s[i+ptr] != me[i]) return false;
}
return +ptr >= lim || isSepar(s[+ptr]);
} int print(int i, int lim)
{
if(isCanYou(i+, lim))
{
printf("I can");
i += ;
}
else if(isCouldYou(i+, lim))
{
printf("I could");
i += ;
}
else if(isMe(i+, lim))
{
printf("you");
i += ;
}
else if(i+ < lim && s[i+] == 'I' && (i+ >= lim || isSepar(s[i+])))
{
printf("you");
i += ;
}
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 = -, tp_end = ;
int now_cnt = ;
for(int i=; i<len; i++)
if(s[i] != ' ')
{
tp_begin = i-; break;
}
for(int i=len-; i>=; i--)
if(s[i] != ' ')
{
tp_end = i; break;
} for(int i=tp_begin+; i<=tp_end; i++)
{
if(s[i] == ' ')
{
int j = i+;
while(j <= tp_end && s[j] == ' ') j ++; // i+1~j-1: redundant space
if(!isPunc(s[j]))
s[now_cnt++] = s[i];
i = j-;
}
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 = ;
while(i < now_cnt && s[i] == ' ') i ++; // first un-space
i = print(i-, now_cnt);
for(i=i+;i<now_cnt;i++)
{
if(isSepar(s[i]))
{
printf("%c", s[i]);
i = print(i, now_cnt); }
else printf("%c", s[i]);
} puts("");
}
}
最新文章
- shape--用代码修改shape的颜色属性
- python学习之路-day2-pyth基础2
- 昂贵的聘礼(dijkstra)
- SharePoint 2013 中使用 JavaScript Like 和Unlike list item/page/document
- sublime text配置
- optimize performance
- QT程序启动界面的使用
- unique &;unique_copy
- WindowsService开发遇到的问题
- 固定GridView标题栏,冻结列功能实现
- 【转载】java final 关键字的几种用法
- EF Core 快速上手——EF Core的三种主要关系类型
- .NET Standard 2.0正式发布了
- Zookeeper 分布式机器部署
- MongoDB实战性能优化
- 关于while read line 循环中变量作用域的问题
- 商家中心FAQ
- 牛客练习赛40 A 小D的剧场 (思维dp)
- alpha冲刺7/10
- C语言中的语句