解题思路: 遍历字符串,遇到元音字母即输出位置,否则输出0
注意事项:
参考代码:
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int len = str.length(); //str的长度 for(int i = 0; i < len; i ++) { //遍历字符串 if(str[i] == 'a'|| str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u') { cout << i + 1; //遇到元音字母立即输出位置,并退出整个程序 return 0; } } cout << 0; //这句值20分,程序执行到这里,表示整个字符串没有元音字母,输出0 return 0; }
0.0分
3 人评分