[CF从零单排#4]118A - String Task

题目来源: http://codeforces.com/problemset/problem/118/A

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

题目大意:

给定一个字符串(长度不超过100),你需要做以下处理:

  • 删除所有元音
  • 在所有辅音前面插入一个字符'.'
  • 将大写的辅音字母转化成小写
  • 元音有:a, o, y, e, u, i(不分大小写)

题目分析:

模拟题,先读取字符串s。再新键一个字符串p,我们设想将s中的辅音保存到p中去。输出时,每个辅音前面先输出多一个'.'字符就可以了。

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
	char s[110], p[110];
	cin >> s;
	int len = strlen(s);
	int k = 0;
	for(int i=0; i<len; i++){
		if(s[i]=='A' || s[i]=='a' || s[i]=='O' || s[i]=='o' || s[i]=='Y' || s[i]=='y' || s[i]=='E' || s[i]=='e' || s[i]=='U' || s[i]=='u' || s[i]=='I' || s[i]=='i'){
			continue;
		}else{
			if(s[i]>='A' && s[i]<='Z')
				s[i] += 'a'-'A';
			p[k++] = s[i];
		}
	}
	for(int i=0; i<k; i++)
		cout << '.' << p[i];
	return 0;
}
posted @ 2020-07-23 21:31  gdgzliu  阅读(177)  评论(0)    收藏  举报