当前位置:网站首页>L1-064 估值一亿的AI核心代码 (20 分) 格式错误
L1-064 估值一亿的AI核心代码 (20 分) 格式错误
2022-04-22 06:17:00 【S atur】
题意:

思路:
· 个人思路是先处理原文串a所有空格和大小写变成串b
· 再处理串b中的各种替换问题,由于在处理单词替换时虽然先考虑的“I”的替换,但是之后再不会变量到该单词,所以并未出现大家所说的测试点2(can you)的卡顿。
· 但是特别注意这个题的另外一个坑点,本人就是一直测试点1和测试点4格式错误,后面通过这篇博客的详细讲解才通过了本题。
· 测试点1:结尾没有标点符号而有多个空格
· 测试点4:三个空格,要求输出"AI: "即可。
AC代码:
#include<bits/stdc++.h>
#define int long long
//#define endl '\n'
using namespace std;
const int N = 1e5+10;
int n;
string a, b, c;
bool check(int x, int sz, int len)
{
if((x==0||b[x-1]==' '||ispunct(b[x-1]))&&(x+(sz-1)==len||b[x+sz]==' '||ispunct(b[x+sz]))) return 1;
return 0;
}
signed main()
{
cin >> n;
getchar();
while(n--){
a.clear(); b.clear(); c.clear();
getline(cin, a);
cout << a << endl;
int len = a.size()-1;
for(int i = 0; i <= len; i ++){
if(a[i]==' '){
// cout << "i: " << i << endl;
if(!b.size()||i==len) continue;
int ok = 0;
for(int j = i+1; j <= len; j ++){
if(a[j]==' ') continue;
else if(i==len){
i = j-1;
ok = 1;
break;
}
else if(ispunct(a[j])){
i = j;
ok = 1;
if(a[j]=='?') b += '!';
else b += a[j];
break;
}
else{
ok = 1;
if(b.size()) b += ' ';
i = j-1;
break;
}
}
}
else if(isupper(a[i])&&a[i]!='I') b += tolower(a[i]);
else if(a[i]=='?') b += '!';
else b += a[i];
}
// cout << "size: " << b.size() << endl;
// cout << b << endl;
len = b.size()-1;
for(int i = 0; i <= len; i ++){
// cout << "i: " << i << endl;
if(b[i]=='I'&&check(i, 1, len)){
c += "you";
continue;
}
if(b[i]=='m'&&b[i+1]=='e'&&check(i, 2, len)){
c += "you";
i++;
continue;
}
if(i+6<=len){
string tmp = b.substr(i, 7);
if(tmp=="can you"&&check(i, 7, len)){
c += "I can";
i += 6;
continue;
}
}
if(i+8<=len){
string tmp = b.substr(i, 9);
if(tmp=="could you"&&check(i, 9, len)){
c += "I could";
i += 8;
continue;
}
}
c += b[i];
}
// cout << "size: " << c.size() << "c:" << c << "endl" << endl;
cout << "AI: " << c << endl;
}
return 0;
}
/*
Hello ?
AI: hello!
Good to chat with you
AI: good to chat with you
can you speak Chinese?
AI: I can speak chinese!
Really?
AI: really!
Could you show me 5
AI: I could show you 5
What Is this prime? I,don 't know
AI: what Is this prime! you,don't know
*/
版权声明
本文为[S atur]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Satur9/article/details/123597608
边栏推荐
- [number theory] prime number (2): prime number sieve method (Egyptian sieve, Euler sieve, interval sieve)
- Interviewers often ask about the general process and special circumstances of object allocation
- 1232 · 爆破气球的最小箭头数
- SQL review, grammar notes, fresh out
- 链表习题详解
- 详解冒泡序列与数组名
- LaTex用模板的时候图片的caption标题无法左对齐
- 单例池、单例Bean、单例模式
- Pycharm only needs five steps to improve the download speed by using Tsinghua image source
- P1095 [NOIP2007 普及组] 守望者的逃离
猜你喜欢

LeetCode - 4 - (接雨水、无重复字符的最长子串、分发糖果、二叉树的<前中后层>序遍历)

在类加载的过程中,类变量的分配区域和实例变量的分配区域不一样

(2) Basic configuration of SQL server and connection to SQL server using Navicat
![P1095 [NOIP2007 普及组] 守望者的逃离](/img/5e/0437bdee83b6b66626e535e382b84b.png)
P1095 [NOIP2007 普及组] 守望者的逃离

Redis advanced

Binary tree chain structure operation leetcode + Niuke (detailed explanation)

LeetCode - 7 - (二叉树的最近公共祖先、轮转数组、二叉树的直接、下一个排列、组合总和)

面试官常问的,对象分配的一般过程及特殊情况

LeetCode - 6 - (字符串相乘、下一个更大元素<ⅠⅡⅢ>、k个一组翻转链表)

最强数组学习之路
随机推荐
Interviewers often ask about the general process and special circumstances of object allocation
384 · 最长无重复字符的子串
Anaconda installation and use
【数论】素数(五):梅森素数(Lucas_Lehmer判定法)
Binary tree chain structure operation leetcode + Niuke (detailed explanation)
递归反转链表
L2-005 集合相似度(set判重)
Win10 Anaconda install cocotb
树+二叉树 详解 详解 +Top-k问题
1. Compile the following three modules of student information management system: and detect the implementation. 1. Add student information 4. Query student information 5. Query all student information
内部类使用说明(静态、实例、局部)
838 · 子数组和为K
LaTex中添加作者照片和作者简介
面试官常问的,对象分配的一般过程及特殊情况
LaTex用模板的时候图片的caption标题无法左对齐
Codeforces Round #778
332 · 恢复数组
278 · 绘制填充
LeetCode - 4 - (接雨水、无重复字符的最长子串、分发糖果、二叉树的<前中后层>序遍历)
LeetCode - 6 - (字符串相乘、下一個更大元素<ⅠⅡⅢ>、k個一組翻轉鏈錶)