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.

Examples
Input
tour
Output
.t.r
Input
Codeforces
Output
.c.d.f.r.c.s
Input
aBAcAba
Output
.b.c.b

链接:https://vjudge.net/problem/CodeForces-118A

题目大概意思是:输入一串字符串,删除所有元音,插入一个字符‘.’在每个辅音之前,用相应的小写辅音替换所有大写辅音。

我的思路:先定义一个字符数组和字符指针给其分配堆空间用于储存处理好的数组,先将大写通过数据转换函数全部转化为小写,再将非元音前面加‘.’而元音字母则不作处理。

代码如下:

#include <iostream>
#include <ctype.h>
using namespace std;
int main()
{
	char a[150], *b = new char[250];
	int i, j;
	cin >> a;
	for (i = j = 0; a[i] != '\0'; i++)
	{
		a[i] = tolower(a[i]);
		if (a[i] != 'a' && a[i] != 'o' && a[i] != 'i' && a[i] != 'e' &&a[i] != 'u' &&a[i] != 'y')
		{
			b[2 * j] = '.';
			b[2 * j + 1] = a[i];
			j++;
		}
	}b[2 * j] = '\0'; cout << b;
	delete[]b;
}

猜你喜欢

转载自blog.csdn.net/weixin_43999137/article/details/84866298