题目描述
如今的IM(即时通讯软件)市场竞争十分激烈,腾讯QQ,微软MSN,雅虎通,ICQ,SKYPE,连中国移动都拿新推出的“飞信”来争夺市场份额。因此,如何推出更有吸引力的创新服务,成了吸引用户的关键。聊天机器人正是在这样的历史条件下诞生的,其具有类似于人工智能的对话能力和贴近人类语言习惯的对话方式吸引了不少喜欢新奇的人的眼球。现在我们也来做一个聊天机器人,当然,在要求上适可而止,只要会以下几句对话就可以了: 1、 Q:Hello. A:Hello. 2、 Q:How are you? A:I’m fine. 3、 Q:How old are you? A:I’m (回答次数)’s old. 4、 Q:What’s your name? A1:My name is LittleCpp.(第一次提此问题答案) A2:I think I had told you yet.(第二次提此问题答案) A3:Oh, you have a poor memory.(第三次及以后提此问题答案) 5、 Q:Bye. A:See you.(同时终止程序) 其机器人名为LC,当你问这些问题(只能问上述问题)时,机器人会给你一个满意的答复。
输入
输入含有一些问题,问题为上述的英文句子,每句话第一个字母为大写,单词I为大写。
输出
每一问题在回答前先输出“LC:”。 当输入问题1、2,输出相应答案; 当输入问题3,问多大时,以回答问题的次数作答(包含本问题); 当第一次输入问题4时,输出A1,当第二次输入问题4时,输出A2,当第三次及以后输入问题4时,输出A3; 当输入问题5时,输出相应问题并终止程序。 输入上述问题以外的问题时,输出“Sorry, my father haven’t taught me how to answer this question.”。
样例输入
Hello.
How are you?
What’s your name?
How old are you?
What’s your name?
Bye.
Hello.
样例输出
LC:Hello.
LC:I’m fine.
LC:My name is LittleCpp.
LC:I’m 4’s old.
LC:I think I had told you yet.
LC:See you.
挺简单的,用if语句判断就可以了。
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s[10000];
int k;
k=0;
int i=0;
while(getline(cin,s[i]))
{
if(s[i]=="Hello."){cout<<"LC:Hello."<<endl;}
else if(s[i]=="How are you?"){cout<<"LC:I'm fine."<<endl;}
else if(s[i]=="What's your name?")
{
if(k==1){cout<<"LC:I think I had told you yet."<<endl;k++;}
else if(k==2)cout<<"LC:Oh, you have a poor memory."<<endl;
else {cout<<"LC:My name is LittleCpp."<<endl;k++;}
}
else if(s[i]=="How old are you?"){cout<<"LC:I'm "<<i+1<<"'s old."<<endl;}
else if(s[i]=="Bye."){cout<<"LC:See you."<<endl;break;}
else cout<<"LC:Sorry, my father haven’t taught me how to answer this question."<<endl;
i++;
}
return 0;
}