L1-035 情人节(string)

https://images.ptausercontent.com/356

以上是朋友圈中一奇葩贴:“2月14情人节了,我决定造福大家。第2个赞和第14个赞的,我介绍你俩认识…………咱三吃饭…你俩请…”。现给出此贴下点赞的朋友名单,请你找出那两位要请客的倒霉蛋。

输入格式:

根据点赞情况在一行中输出结论:若存在第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个空格。如果有并列,则输出编号最大的那个。

输入样例1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
GaoXZh
Magi
Einst
Quark
LaoLao
FatMouse
ZhaShen
fantacy
latesum
SenSen
QuanQuan
whatever
whenever
Potaty
hahaha
.

输出样例1:

1
Magi and Potaty are inviting you to dinner...

输入样例2:

1
2
3
4
LaoLao
FatMouse
whoever
.

输出样例2:

1
FatMouse is the only one for you...

输入样例3:

1
2
LaoLao
.

输出样例3:

1
Momo... No one is for you ...

思路:

判断是否存下第2和第14的字符串,选择语句输出。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <bits/stdc++.h>
using namespace std;

int cnt = 0;
string s, A = "", B = "";

int main()
{
while(1)
{
cin >> s;
if(s == ".")
break;
cnt++;
if(cnt == 2)
A = s;
else if(cnt == 14)
B = s;
}
if(A == "")
cout << "Momo... No one is for you ...";
else if(B == "")
cout << A << " is the only one for you...";
else
cout << A << " and " << B << " are inviting you to dinner...";

return 0;
}