ACM第一题

题目:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:

deletes all the vowels,
inserts a character “.” before each consonant,
replaces all uppercase consonants with corresponding lowercase ones.

Vowels are letters “A”, “O”, “Y”, “E”, “U”, “I”, and the rest are consonants. The program’s input is exactly one string, it should return the output as a single string, resulting after the program’s processing the initial string.
Help Petya cope with this easy task

Input
The first line represents input string of Petya’s program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.

Output
Print the resulting string. It is guaranteed that this string is not empty.

题目分析:
将一个含有大小写元辅音字母的字符串删除掉其中的元音,将大写字母改为小写字母,并在在每个辅音之前插入一个字符“.” 。

代码片:

#include
using namespace std;
int main()
{
 char a[100] = { "aBAcAba" }; int n;
 n = strlen(a);
 for (int i = 0; i < n; ++i)
 {
  if (a[i] == 'a'&&a[i] == 'e'&&a[i] == 'i'&&a[i] == 'o'&&a[i] == 'u'&&a[i] == 'y'&&a[i] == 'A'&&a[i] == 'E'&&a[i] == 'I'&&a[i] == 'O'&&a[i] == 'U'&&a[i] == 'Y')
  {
   a[i] ='DEL';//删除元音
  }
  if (a[i] >= 'A'&&a[i] <= 'Z')
  {
   a[i] += 32;//转换成小写
  }
  if (a[i] != 'a'&&a[i] != 'e'&&a[i] != 'i'&&a[i] != 'o'&&a[i] != 'u'&&a[i] != 'y')
   cout << "." << a[i];//在每个辅音之前插入一个字符“.”
 }
 system("pause");
}

有点小瑕疵…

你可能感兴趣的:(ACM第一题)