题解:接收输⼊,当输⼊为”.”的时候退出循环,每次接收⼀个输⼊就将cnt++。如果当前cnt==
2或者==
4就将结果保存到string a或者string b中,最后根据cnt不同的值输出不同的结果。
#include <iostream>
using namespace std;
int main()
{
string a, b, str;
int cnt = 0;
while (cin >> str)
{
if (str == ".")
break;
cnt++;
if (cnt == 2)
a = str;
if (cnt == 14)
b = str;
}
if (cnt >= 14)
cout << a << " and " << b << " are inviting you to dinner...";
else if (cnt <= 1)
cout << "Momo... No one is for you ...";
else
cout << a << " is the only one for you...";
return 0;
}