公式
A - Misdelivery 解説 by en_translator
For beginners
- If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
- Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
- 「競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
- 「Python入門 AtCoder Programming Guide for beginners (APG4bPython)」 is a Python tutorial for competitive programmers. Again, this is only in Japanese.
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");
}
}
}
投稿日時:
最終更新: