String Task

题目

A. 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:

  1. deletes all the vowels,
  2. inserts a character “.” before each consonant,
  3. 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.

题解

给定字符串,包含大小写的拉丁字母

  1. 删除所有元音,
  2. 在每个辅音之前插入“ . ”,
  3. 将所有大写辅音替换成相应的小写辅音;
  4. 元音字母包含 A,O,Y,E,U,I;
  5. 进程输入是一个字符串,它以单个字符串的形式返回输出,这是进程处理初始字符串后的结果

Input

第一行表示输入的字符串,改字符串仅由大写和小写拉丁字母组成,长度从0~100;
Output
打印结果字符串,可以保证这个字符串不为空。

思路

​ 分别定义一个输入的字符串in[100]和输出的字符串ou[100],将输出的字符串ou[100]的所有字符初始化为 ‘ . ‘ ;然后先将输入字符串的所有大写字母转换为小写;之后通过if语句判断是否为辅音字母;是辅音字母则间位提取至输出字符串ou[100]中。最后所得到的ou[100]则可以直接输出。

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

using namespace std;
int ()
{
char in[100],ou[100];
for (int i = 0; i < 100; i++)
ou[i] = '.';
cin >>in;
int j = 1, num = 0;
for (int i = 0; i < strlen(in);i++)
{
if (in[i] >= 65 && in[i] <= 90)
in[i] += 32;
if (in[i] != 'a' && in[i] != 'o' && in[i] != 'y' && in[i] != 'e' && in[i] != 'u' &&in[i] != 'i')
{
ou[j] = in[i];
num++;
j += 2;
}//如果是辅音则间位提取
}
for (j = 0; j < 2 * num; j++)
cout << ou[j];
cout << endl;
system("pause");
}

原文引用 大专栏  https://www.dazhuanlan.com/2019/08/27/5d64bad28c43b/


上一篇:2020年4月12日个人赛


下一篇:nexus配置LDAP