分很菜…

以后写题一定记得把题意理清楚了再开始写。

模拟题还是大坑,代码还是写得不够多,代码量一大就写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("");
}
}

最新文章

  1. shape--用代码修改shape的颜色属性
  2. python学习之路-day2-pyth基础2
  3. 昂贵的聘礼(dijkstra)
  4. SharePoint 2013 中使用 JavaScript Like 和Unlike list item/page/document
  5. sublime text配置
  6. optimize performance
  7. QT程序启动界面的使用
  8. unique &amp;unique_copy
  9. WindowsService开发遇到的问题
  10. 固定GridView标题栏,冻结列功能实现
  11. 【转载】java final 关键字的几种用法
  12. EF Core 快速上手——EF Core的三种主要关系类型
  13. .NET Standard 2.0正式发布了
  14. Zookeeper 分布式机器部署
  15. MongoDB实战性能优化
  16. 关于while read line 循环中变量作用域的问题
  17. 商家中心FAQ
  18. 牛客练习赛40 A 小D的剧场 (思维dp)
  19. alpha冲刺7/10
  20. C语言中的语句

热门文章

  1. eclipse上导入import git项目
  2. HDU1024_Max Sum Plus Plus【滚动数组】
  3. 学习笔记—— 一些UPDATE语句
  4. 牛逼的postman,分类管理更好用
  5. wesome-android
  6. Python入门 五、学着机器思考
  7. Ruby类扩张(extension)
  8. PowerDesigner常用技巧
  9. 如何在linux下搭建svn服务
  10. 禁止tomcat扫描jar包的tld文件