本题要求你实现一个稍微更值钱一点的 AI 英文问答程序,规则是:
I
;can you
、could you
对应地换成 I can
、I could
—— 这里“独立”是指被空格或标点符号分隔开的单词;I
和 me
换成 you
;?
换成惊叹号 !
;输入首先在第一行给出不超过 10 的正整数 N,随后 N 行,每行给出一句不超过 1000 个字符的、以回车结尾的用户的对话,对话为非空字符串,仅包括字母、数字、空格、可见的半角标点符号。
按题面要求输出,每个 AI 的回答前要加上 AI:
和一个空格。
6
Hello ?
Good to chat with you
can you speak Chinese?
Really?
Could you show me 5
What Is this prime? I,don 't know
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
写了快两个小时,头晕眼花,不知自己是谁,想了无数样例依然只有19分。。。希望有大佬能。。给个错误样例。。感谢!
#include
#include
#include
#include
using namespace std;
char ch[10010];
char canyou[] = "can you";
char couldyou[] = "could you";
void delSpace(int x,int sl,int l);
int isCan(int x);
int isCould(int x);
void delSpace(int x,int sl,int l)
{
for(int i=x; i s1;
stack s2;
while(!s1.empty()) s1.pop();
while(!s2.empty()) s2.pop();
for(int i=0; i='A' && ch[i]<='Z' && ch[i]!='I')
ch[i]+=32;
s1.push(ch[i]);
}
while(!s1.empty())
{
char cs = s1.top();
s1.pop();
if(s2.empty() && cs!=' ')
s2.push(cs);
else
{
if(cs == ' ' && s2.empty())
continue;
else if(cs == ' ' && cs == s2.top())
continue;
else s2.push(cs);
}
}
l = 0;
while(!s2.empty())
{
ch[l++] = s2.top();
s2.pop();
}
/* for(int i=0; i=0; i--)
{
if(ch[i] == ' ')
l--;
else break;
}
int ff = 0;
for(int i=0; i=0 && i+1 l)
printf("c");
else
{
if(isCan(i,l) && !isdigit(ch[i+7]) &&!isalpha(ch[i+7]))
{
printf("I can");
i+=6;
}
else printf("c");
}
}
else if(i>0)
{
if(isdigit(ch[i-1] )|| isalpha(ch[i-1]))
{
printf("c");
continue;
}
if(i+7 == l)
{
if(isCan(i,l))
{
printf("I can");
i+=6;
}
else printf("c");
}
else if(i+7 > l)
printf("c");
else
{
if(isCan(i,l) && !isdigit(ch[i+7]) &&!isalpha(ch[i+7]))
{
printf("I can");
i+=6;
}
else printf("c");
}
}
}
else if(ch[i] == 'c'&& i+9<=l&&isCould(i,l))
{
if(i==0)
{
if(i+9 == l)
{
if(isCould(i,l))
{
printf("I could");
i+=8;
}
else printf("c");
}
else if(i+9 > l)
printf("c");
else
{
if(isCould(i,l) && !isdigit(ch[i+9]) &&!isalpha(ch[i+9]))
{
printf("I could");
i+=8;
}
else printf("c");
}
}
else if(i>0)
{
if(isdigit(ch[i-1] )|| isalpha(ch[i-1]))
{
printf("c");
continue;
}
if(i+9 == l)
{
if(isCould(i,l))
{
printf("I could");
i+=8;
}
else printf("c");
}
else if(i+9 > l)
printf("c");
else
{
if(isCould(i,l) && !isdigit(ch[i+9]) &&!isalpha(ch[i+9]))
{
printf("I could");
i+=8;
}
else printf("c");
}
}
}
else if(ch[i] == 'I')
{
if(i==0)
{
if(i+1=2 && ch[i+1]=='e')
{
if(l==2)
{
printf("you");
i++;
}
else if(l>=3 && !isdigit(ch[i+2]) && !isalpha(ch[i+2]))
{
printf("you");
i++;
}
else
printf("m");
}
else if(i == l-2)
{
if(ch[i+1] == 'e' &&!isdigit(ch[i-1]) && !isalpha(ch[i-1]))
printf("you"),i++;
else printf("m");
}
else
{
if(ch[i+1]=='e' && !isdigit(ch[i-1]) &&!isalpha(ch[i-1]) && !isdigit(ch[i+2]) && !isalpha(ch[i+2]))
printf("you"),i++;
else printf("m");
}
}
else if(ch[i] == '?')
printf("!");
else printf("%c",ch[i]);
}
printf("\n");
}
return 0;
}