A - Leftrightarrow Editorial by en_translator
A length-\(N\) bidirectional arrow string \((3\leq N\leq 100)\) always consists of one <
, \((N-2)\) copies of =
, and one >
, concatenated in this order. Conversely, under the constraints \(3\leq N\leq 100\), such a string always satisfies the condition of being a bidirectional arrow string.
Thus, it is sufficient to check if the given string is of this type. Specifically, check if
- the first character is
<
, - the \(N\)-th character is
>
, and - the \(i\)-th character is
=
for all \(2\leq i\leq N-1\).
If the answers to all of the questions are Yes
, then the answer is Yes
; otherwise, the answer is No
.
This can be implemented with an if
statement and a for
statement.
Sample code in C++:
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin>>s;
int n=s.size();
if(s[0]!='<'){
cout<<"No"<<endl;
return 0;
}
if(s[n-1]!='>'){
cout<<"No"<<endl;
return 0;
}
for(int i=1;i<n-1;i++){
if(s[i]!='='){
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
return 0;
}
Sample code in Python:
s=input()
flag=True
if s[0]!='<':
flag=False
if s[-1]!='>':
flag=False
for i in range(1,len(s)-1):
if s[i]!='=':
flag=False
if flag:
print("Yes")
else:
print("No")
posted:
last update: