2019浙江省赛F题 Abbreviation

题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4105
Abbreviation

In the Test of English as a Foreign Language (TOEFL), the listening part is very important but also very hard for most students since it is usually quite hard for them to remember the whole passage. To help themselves memorize the content, students can write down some necessary details. However, it is not easy to write down the complete word because of its length. That’s why we decide to use the abbreviation to express the whole word.

It is very easy to get the abbreviation, all we have to do is to keep the consonant letters and erase the vowel. In the English alphabet, we regard ‘a’, ‘e’, ‘i’, ‘y’, ‘o’, ‘u’ as the vowels and the other letters as the consonants. For example, “subconscious” will be expressed as “sbcnscs”.

However, there is one exception: if the vowel appears as the first letter, they should be kept instead of thrown away. For example, “oipotato” should be expressed as “optt”.

Since you have learned how to use the abbreviation method, it’s time for some exercises. We now present you
words in total, it’s your task to express them in their abbreviation form.

Input

There are multiple test cases. The first line of the input contains an integer T (about 100), indicating the number of test cases. For each test case:

The only line contains a string s (1<=|s|<=100) consisting of lowercase English letters, indicating the word which needs to be abbreviated.

Output

For each test case output one line containing one string, which is the correct abbreviation of the given word.

Sample Input

5
subconscious
oipotato
word
symbol
apple

Sample Output

sbcnscs
optt
wrd
smbl
appl

解题思路

一道签到题。对于字符串中的每个字符ch进行判断,当ch位于第一个字符或者不是 ‘a’, ‘e’, ‘i’, ‘y’, ‘o’, 'u’时就输出即可

代码

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;


int funct(char ch)
{
	if (ch != 'a'&&ch != 'e'&&ch != 'i'&&ch != 'o'&&ch != 'u'&&ch!='y')
		return 1;
	else
		return 0;
}

int main() 
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		string str, ans;
		cin >> str;
		int i, j;
		for (i = 0; i < str.size(); i++)
		{
			if(i==0||funct(str[i]))
				ans+=str[i];
		}
		cout << ans << endl;
	}
	return 0;
}

你可能感兴趣的:(题解)