CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation
Posted lu1nacy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation相关的知识,希望对你有一定的参考价值。
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name ss can transform to another superhero with name tt if ss can be made equal to tt by changing any vowel in ss to any other vowel and any consonant in ss to any other consonant. Multiple changes can be made.
In this problem, we consider the letters ‘a‘, ‘e‘, ‘i‘, ‘o‘ and ‘u‘ to be vowels and all the other letters to be consonants.
Given the names of two superheroes, determine if the superhero with name ss can be transformed to the Superhero with name tt.
The first line contains the string ss having length between 11 and 10001000, inclusive.
The second line contains the string tt having length between 11 and 10001000, inclusive.
Both strings ss and tt are guaranteed to be different and consist of lowercase English letters only.
Output "Yes" (without quotes) if the superhero with name ss can be transformed to the superhero with name tt and "No" (without quotes) otherwise.
You can print each letter in any case (upper or lower).
a u
Yes
abc ukm
Yes
akm ua
No
In the first sample, since both ‘a‘ and ‘u‘ are vowels, it is possible to convert string ss to tt.
In the third sample, ‘k‘ is a consonant, whereas ‘a‘ is a vowel, so it is not possible to convert string ss to tt.
思路:签到题,就是元音和辅音相同位置的相同的话,输出Yes,不同的话输出No;
注意
strlen()函数求出的字符串长度为有效长度,既不包含字符串末尾结束符 ‘ ’;
sizeof()操作符求出的长度包含字符串末尾的结束符 ‘ ’;
当在函数内部使用sizeof()求解由函数的形参传入的字符数组的长度时,得到的结果为指针的长度,既对应变量的字节数,而不是字符串的长度,此处一定要小心。
代码如下:
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 5 int vow(char a,char b) 6 { 7 if(a == b) 8 return 1; 9 else if(a == ‘a‘ || a == ‘o‘ || a == ‘e‘ || a == ‘i‘ || a == ‘u‘) 10 { 11 if(b == ‘a‘ || b == ‘o‘ || b == ‘e‘ || b == ‘i‘ || b == ‘u‘)//元元 12 return 1; 13 else//元辅 14 return 0; 15 } 16 else if(b == ‘a‘ || b == ‘o‘ || b == ‘e‘ || b == ‘i‘ || b == ‘u‘)//辅元 17 return 0; 18 //辅辅 19 return 1; 20 } 21 int main() 22 { 23 string s,t; 24 while(cin >> s >> t) 25 { 26 int sl = s.size(); 27 int tl = t.size(); 28 if(sl != tl) 29 { 30 cout << "No" << endl; 31 continue; 32 } 33 bool flag = 0; 34 for(int i = 0;i < sl;i++) 35 { 36 if(vow(s[i],t[i]) == 0) 37 { 38 cout << "No" << endl; 39 flag = 1; 40 break; 41 } 42 } 43 if(flag == 0) 44 cout << "Yes" << endl; 45 } 46 return 0; 47 }
以上是关于CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation的主要内容,如果未能解决你的问题,请参考以下文章
CodeCraft-19 and Codeforces Round #537 (Div. 2)
CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation
CodeCraft-19 and Codeforces Round #537 (Div. 2) - D. Destroy the Colony(动态规划+组合数学)
CodeCraft-19 and Codeforces Round #537 (Div. 2) 题解
CodeCraft-19 and Codeforces Round #537 (Div. 2) B. Average Superhero Gang Power