【PTA】练习集——情人节

输入格式:

输入按照点赞的先后顺序给出不知道多少个点赞的人名,每个人名占一行,为不超过10个英文字母的非空单词,以回车结束。一个英文句点.标志输入的结束,这个符号不算在点赞名单里。

输出格式:

根据点赞情况在一行中输出结论:若存在第2个人A和第14个人B,则输出“A and B are inviting you to dinner...”;若只有A没有B,则输出“A is the only one for you...”;若连A都没有,则输出“Momo... No one is for you ...”。

输入样例1:

GaoXZh
Magi
Einst
Quark
LaoLao
FatMouse
ZhaShen
fantacy
latesum
SenSen
QuanQuan
whatever
whenever
Potaty
hahaha
.
 

输出样例1:

Magi and Potaty are inviting you to dinner...

输入样例2:

LaoLao
FatMouse
whoever
.

输出样例2:

FatMouse is the only one for you...

输入样例3:

LaoLao
.

输出样例3:

Momo... No one is for you ...
C++版本源代码:
 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     string str[100];
 8     string str1;
 9     int n=100;
10     int i=0;
11     cin >> str1;
12     while (str1 != ".")
13     {
14         str[i] = str1;
15         i++;
16         cin >> str1;
17     }
18     if (i < 2) cout << "Momo... No one is for you ..." << endl;
19     else if (i >= 2 && i < 14) cout << str[1] << " is the only one for you..." << endl;
20     else cout << str[1] << " and " << str[13] <<" are inviting you to dinner..." << endl;
21     return 0;
22 }
 

猜你喜欢

转载自www.cnblogs.com/Andre/p/12179905.html