B - Pentagon Editorial
/
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200200 points
Problem Statement
A regular pentagon �P is shown in the figure below.
Determine whether the length of the line segment connecting points �1S1 and �2S2 of �P equals the length of the line segment connecting points �1T1 and �2T2.
Constraints
- Each of �1S1, �2S2, �1T1, and �2T2 is one of the characters
A
,B
,C
,D
, andE
. - �1≠�2S1=S2
- �1≠�2T1=T2
Input
The input is given from Standard Input in the following format:
�1�2S1S2 �1�2T1T2
Output
If the length of the line segment connecting points �1S1 and �2S2 of �P equals the length of the line segment connecting points �1T1 and �2T2, print Yes
; otherwise, print No
.
Sample Input 1Copy
Copy
AC EC
Sample Output 1Copy
Copy
Yes
The length of the line segment connecting point A
and point C
of �P equals the length of the line segment connecting point E
and point C
.
Sample Input 2Copy
Copy
DA EA
Sample Output 2Copy
Copy
No
The length of the line segment connecting point D
and point A
of �P does not equal the length of the line segment connecting point E
and point A
.
Sample Input 3Copy
Copy
BD BD
Sample Output 3Copy
Copy
Yes
#include<iostream>
using namespace std;
int main()
{
string a;
string b;
cin>>a>>b;
if(a==b)
{
cout<<"Yes";
return 0;
}
if(a[1]==b[1])
{
if((a[0]+2==a[1]||a[0]-2==a[1])&&(b[0]+2==b[1]||b[0]-2==b[1]))
{
cout<<"Yes";
return 0;
}
if((a[0]+1==a[1]||a[0]-1==a[1])&&(b[0]+1==b[1]||b[0]-1==b[1]))
{
cout<<"Yes";
return 0;
}
else
{
cout<<"No";
return 0;
}
}
if((a[0]+1==a[1]||a[0]-1==a[1])&&(b[0]+1==b[1]||b[0]-1==b[1]))
{
cout<<"Yes";
return 0;
}
if(a[0]+4==a[1]||a[0]-4==a[1]||b[0]+4==b[1]||b[0]-4==b[1])
{
if(b[0]+2==b[1]||b[0]-2==b[1]){
cout<<"No";
return 0;
}
cout<<"Yes";
return 0;
}
else
{
cout<<"No";
return 0;
}
return 0;
}