Blue Bridge Cup algorithm training 6-3 to determine character position

Returns the position of the first occurrence of a vowel in the given string s. There are only five vowels in English: 'a', 'e', ​​'i', 'o', and 'u'.
  Returns 0 if there are no vowels in the string.
  Only lowercase cases are considered.
sample input
and
Sample output

1


Code:

#include <iostream>
#include <string>
using namespace std;

intmain()
{
	string s;
	cin >> s;
	int len = s.length();
	for(int i = 0; i < len; i++)
	{
		if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
		{
			cout << i+1;
			return 0;
		}
	}
	cout << 0;
	return 0;
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324822171&siteId=291194637