The Nicest Word(io优化)

题目描述
It is known that if a word has more vowels, the word sounds better(the nicer the word is). To be more specific, a word’s nice degree is calculated according to the following three rules.
I. Every lowercase vowel letters(a, e, i, o, u)in the word can contribute 5 score to the word.
II. Every lowercase consonant letters(all letters except five vowel letters)in the word can contribute 1 score to the word.
III. Every uppercase letter can contribute as twice an its corresponding lowercase letter contributed to the word.
Now your task is to find the nicest word among a word list.

输入格式
There are multiple test cases.
For each case, the first line contains one integer N, represent the number of the words in the list. Then following N lines, each line contains a non-empty word consist of only lowercase letters and uppercase letters.
The number of the N word’s total letters is no larger than 1000000.
If N is zero, that is the end of input.

输出格式
For each test case, output the nicest word’s score in a single line.

样例输入
3
Abc
Bcd
AEIOU
0

样例输出
50

来源
2014 ACM 黑龙江省赛 热身赛 第一题

#include<iostream>
using namespace std;
int a[256];
int main(){
    
    
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    for(int i='a';i<='z';i++)
    	a[i]=1;
    for(int i='A';i<='Z';i++)
    	a[i]=2;
	a['a']=a['e']=a['i']=a['o']=a['u']=5;
	a['A']=a['E']=a['I']=a['O']=a['U']=10;
	while(cin>>n&&n){
    
    
		string str;
		int ans=0;
		for(int i=0;i<n;i++){
    
    
			cin>>str;
			int score=0,l=str.length();
			for(int j=0;j<l;j++)
				score+=a[str[j]];
			ans=max(ans,score);
		}
		cout<<ans<<endl;
	}
}

猜你喜欢

转载自blog.csdn.net/m0_51794965/article/details/111475209