1. 程式人生 > >ACM第一期練習題第一小題:String Task

ACM第一期練習題第一小題:String Task

click here to have a try
Time limit 2000ms
Memory limit 262144KB

題目原題:
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.

Examples
Input
tour

Output
.t.r

Input


Codeforces

Output
.c.d.f.r.c.s

Input
aBAcAba

Output
.b.c.b

問題簡述:
把第一行輸入的字母串裡的母音字母去掉,然後在剩下的字母前加個“."在下一行輸出。

問題分析:
考慮把大寫字母化成小寫字母,以及把其中的母音字母跳過(即相當於刪除).
VS中通過的程式碼如下:

#include <iostream> 
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	char a[105];
	int i,
length; cin >> a; length = strlen(a); for (i = 0;i < length;i++) { if (a[i] == 'a' || a[i] == 'A' || a[i] == 'o' || a[i] == 'O' || a[i] == 'y' || a[i] == 'Y' || a[i] == 'e' || a[i] == 'E' || a[i] == 'u' || a[i] == 'U' || a[i] == 'i' || a[i] == 'I') { continue; } else { if (a[i] >= 'A'&&a[i] <= 'Z') { a[i] = a[i] + 32; } printf(".%c", a[i]); } } printf("\n"); return 0; }