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;
}
最后
以上就是朴素冰淇淋最近收集整理的关于ACM第一期练习题第一小题:String Task的全部内容,更多相关ACM第一期练习题第一小题:String内容请搜索靠谱客的其他文章。
发表评论 取消回复