Official

A - Weak Beats Editorial by en_translator


Receive the string \(S\) from the standard input, and just as instructed in the problem statement, check if the \(i\)-th character of \(S\) is 1 for all even number \(i\) between \(2\) and \(16\). This can be implemented with a for statement and a if statement. This time, the length of the string is fixed, and so is the indices of characters to be inspected: \(2,4,6,8,10,12,14,16\). Thus, using only an if statement is also feasible. Therefore, the problem has been solved.

Here are caveats on implementation.

When referring to a character in a string, beware that most language adopts zero-based indexing. That is, if a variable \(s\) stores a string, \(s[0]\) represents the first character, \(s[1]\) the second, …, and so on. In our problem, we have to inspect \(s[1],s[3],\ldots,\) and \(s[15]\), instead of \(s[2],s[4],\ldots\), and \(s[16]\); notice the difference in indices.

Also, be careful not to print No multiple times if there are multiple even number \(i\) such that the \(i\)-th character of \(S\) is 1. It is good idea to terminate the program immediately once printing No, or manage a boolean type variable and print only once at last.

Sample code in C++:

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

int main(void) {
	string s;
	cin>>s;
	for(int i=1;i<16;i+=2){
		if(s[i]!='0'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Sample code in Python:

s=input()

flag=True
for i in range(1,16,2):
	if s[i]!='0':
		flag=False

if flag:
	print("Yes")
else:
	print("No")

posted:
last update: