公式
A - パスワード照合 / Password Verification 解説
by
A - パスワード照合 / Password Verification 解説
by
kyopro_friends
初心者の方へ
- AtCoder をはじめたばかりで何をしたらよいか分からない方は、まずは practice contest の問題A「Welcome to AtCoder」を解いてみてください。基本的な入出力の方法が載っています。
- また、プログラミングコンテストの問題に慣れていない方は、AtCoder Beginners Selection の問題をいくつか解いてみることをおすすめします。
- C++入門 AtCoder Programming Guide for beginners (APG4b) は、競技プログラミングのための C++ 入門用コンテンツです。
- Python入門 AtCoder Programming Guide for beginners (APG4bPython) は、競技プログラミングのための Python 入門用コンテンツです。
問題文の指示通り、与えられた文字列についてそれぞれ、正しいパスワードと判定されるかどうかを確かめます。多くのプログラミング言語では、添字が \(0\) から始まることに注意してください。
実装例 (C++)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, m, q;
cin >> n >> m >> q;
vector<pair<int,char>>pc(m);
for(int i=0; i<m; i++){
int p;
char c;
cin >> p >> c;
pc[i] = {p-1, c};
}
for(int i=0; i<q; i++){
string t;
cin >> t;
bool ok = true;
for(int j=0; j<m; j++){
auto[p, c] = pc[j];
if(t[p] != c){
ok = false;
}
}
if(ok){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}
}
実装例 (Python)
N, M, Q = map(int, input().split())
PC = []
for _ in range(M):
p, c = input().split()
PC.append((int(p)-1, c))
for _ in range(Q):
T = input()
if all(T[p] == c for p, c in PC):
print("Yes")
else:
print("No")
投稿日時:
最終更新:
