A - Repdigit 解説 by en_translator
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” (https://atcoder.jp/contests/abs).
Original proposer: admin
We can receive \(N\) as a string and check if the first, second, and third characters are all equal. To check the equality, one may use an if statement, or sort it and check if the first and the last are equal.
Alternatively, one may solve it by using the property that the answer is Yes if and only if \(111\) divides \(N\).
Sample code in C++ 1:
#include <bits/stdc++.h>
using namespace std;
int main(){
string N;cin>>N;
if(N[0]==N[1]&N[1]==N[2]){
cout<<"Yes"<<"\n";
}
else{
cout<<"No"<<"\n";
}
}
Sample code in C++ 2:
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;cin>>N;
if(N%111==0){
cout<<"Yes"<<"\n";
}
else{
cout<<"No"<<"\n";
}
}
Sample code in Python 1:
N=input()
if N[0]==N[1]==N[2]:
print("Yes")
else:
print("No")
Sample code in Python 2:
N=sorted(input())
if N[0]==N[2]:
print("Yes")
else:
print("No")
Sample code in Python 3:
N=input()
if min(N)==max(N):
print("Yes")
else:
print("No")
Sample code in Python 4:
N=int(input())
if N%111==0:
print("Yes")
else:
print("No")
投稿日時:
最終更新: