- Note
- 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() 函数求出的字符串长度为有效长度, 既不包含字符串末尾结束符 '\0';
sizeof() 操作符求出的长度包含字符串末尾的结束符 '\0';
当在函数内部使用 sizeof() 求解由函数的形参传入的字符数组的长度时, 得到的结果为指针的长度, 既对应变量的字节数, 而不是字符串的长度, 此处一定要小心.
代码如下:
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- int vow(char a,char b)
- {
- if(a == b)
- return 1;
- else if(a == 'a' || a == 'o' || a == 'e' || a == 'i' || a == 'u')
- {
- if(b == 'a' || b == 'o' || b == 'e' || b == 'i' || b == 'u')// 元元
- return 1;
- else// 元辅
- return 0;
- }
- else if(b == 'a' || b == 'o' || b == 'e' || b == 'i' || b == 'u')// 辅元
- return 0;
- // 辅辅
- return 1;
- }
- int main()
- {
- string s,t;
- while(cin>> s>> t)
- {
- int sl = s.size();
- int tl = t.size();
- if(sl != tl)
- {
- cout << "No" << endl;
- continue;
- }
- bool flag = 0;
- for(int i = 0;i < sl;i++)
- {
- if(vow(s[i],t[i]) == 0)
- {
- cout << "No" << endl;
- flag = 1;
- break;
- }
- }
- if(flag == 0)
- cout << "Yes" << endl;
- }
- return 0;
- }
来源: http://www.bubuko.com/infodetail-2945127.html