String Task CodeForces-118A解决方法

CodeForces-118A:
Problem Description
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.
Sample Input

tour

Sample Output

.t.r
问题简述:
输入测试例子,即字符串,然后去掉其中所有元音字母,再将所有大写字母用小写字母表示,且要在每个字母前加上’.’,最后输出。
问题分析:
可以利用string头文件,命名一个字符串,再去掉其中的的元音字母,插入所需符号。
c++语言程序:`#include
#include
using namespace std;
int main()
{
string a;
int t;
cin >> a;
t = a.size();
for (int j = 0; j <= a.size()?
{
for (int i = 0; i < 33; i += 32)
{
if (a[j] == (‘A’ + i) || a[j] == (‘E’ + i) || a[j] == (‘I’ + i) || a[j] == (‘O’ + i) || a[j] == (‘U’ + i) || a[j] == (‘Y’ + i)) a=a.erase(j, 1);
if (a.size() < t) i = 2;
}
if (a.size() < t) t–;
else j++;
}
for (int i = 0; i < a.size(); i++)
if (a[i] < 91) a[i] += 32;
for (int i = 0; i < a.size(); i += 2)
a.insert(i,".");
cout << a;

}`

发布了27 篇原创文章 · 获赞 16 · 访问量 1912

猜你喜欢

转载自blog.csdn.net/weixin_43979090/article/details/84861705