Skip to content

L1-035 情人节

img

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

输入格式:

输入按照点赞的先后顺序给出不知道多少个点赞的人名,每个人名占一行,为不超过 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:

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

输出样例 1:

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

输入样例 2:

LaoLao
FatMouse
whoever
.
LaoLao
FatMouse
whoever
.

输出样例 2:

FatMouse is the only one for you...
FatMouse is the only one for you...

输入样例 3:

LaoLao
.
LaoLao
.

输出样例 3:

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

Solution:

java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s = in.readLine();
        List<String> list = new ArrayList<>();
        while (!s.equals(".")) {
            list.add(s);
            s = in.readLine();
        }
        int size = list.size();
        if (size < 2) System.out.println("Momo... No one is for you ...");
        else if (size < 13) System.out.printf("%s is the only one for you...", list.get(1));
        else System.out.printf("%s and %s are inviting you to dinner...", list.get(1), list.get(13));
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s = in.readLine();
        List<String> list = new ArrayList<>();
        while (!s.equals(".")) {
            list.add(s);
            s = in.readLine();
        }
        int size = list.size();
        if (size < 2) System.out.println("Momo... No one is for you ...");
        else if (size < 13) System.out.printf("%s is the only one for you...", list.get(1));
        else System.out.printf("%s and %s are inviting you to dinner...", list.get(1), list.get(13));
    }
}

Released under the MIT License.