公式

A - Misdelivery 解説 by en_translator


For beginners

In short, this problem asks to determine if \(S_X=Y\).

You need to know how to read values from Standard Input, handle arrays, and compare strings.

Note that in most languages, indices of an array start with \(0\).

In some languages like Java, also beware of how to compare strings.

Sample code (Python)

N = int(input())
S = [input() for _ in range(N)]
X, Y = input().split()
X = int(X)

print("Yes" if S[X-1] == Y else "No")

Sample code (C++)

#include<bits/stdc++.h>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<string> S(N);
	for(int i=0; i<N; i++) cin >> S[i];

	int X;
	string Y;
	cin >> X >> Y;
	cout << (S[X-1] == Y ? "Yes" : "No") << endl;
}

Sample code (Java)

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int N = Integer.parseInt(scanner.nextLine());
		String[] S = new String[N];
		for (int i = 0; i < N; i++) {
			S[i] = scanner.nextLine();
		}

		String[] XY= scanner.nextLine().split(" ");
		int X = Integer.parseInt(XY[0]);
		String Y = XY[1];

		if (S[X-1].equals(Y)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

投稿日時:
最終更新: