1. 程式人生 > >訓練題1

訓練題1

題目連結:https://vjudge.net/problem/CodeForces-118A

String Task

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。
我們看到題目有三個要求:
1、清除字串裡所有的母音字母
2、在每個子音字母前面加一個“.”
3、把字串裡的大寫字母換成對應的小寫字母
筆者的程式碼如下:

#include<iostream>
using namespace std;
int main()
{
	char *p;
	p = new char[101];
	cin >> p;  //輸入字串
	for (int i = 0;p[i]!='\0'; i++)
	{
		int k = 1;
		if (p[i] >= 65 && p[i] <= 90)p[i] += 32;  //把大寫字母全部換為小寫字母
		if (p[i] == 'a' || p[i] == 'e' || p[i] == 'i' || p[i] == 'o' || p[i] == 'u' || p[i] == 'y' ||
			p[i] == 'A' || p[i] == 'E' || p[i] == 'I' || p[i] == 'O' || p[i] == 'U' || p[i] == 'Y')k = 0;
		if (k)cout << '.' << p[i];  //對子音字母進行輸出並加"."
	}
	delete[]p;
	system("pause");
}