第一题

String Task

Time limit 2000ms
Memory limit 262144kb

Problem Description

Petya need to write a program which 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.

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

Codeforces

Sample Output

.c.d.f.r.c.s

第一题

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

问题简述:

输入大小写字母进行以下处理

  1. 删除所有元音字母
  2. 在辅音字母前插入字符“.”
  3. 将大写辅音字母转化为小写辅音字母

问题分析:

利用循环先筛掉元音字母,再将大写辅音字母转化为小写辅音字母,再通过循环找到辅音字母利用两次的输出先输出“.”再输出小写辅音字母

程序说明:

用scanf对letter数组进行输入字符串,用strlen计算出输入的长度,用for循环语句和if筛掉大小写的元音字母并改写为‘0’,再通过for循环语句通过大小写相差32将大写转换为小写,最后再通过for循环语句找到之前改写的‘0’输出‘.’和字母

AC通过的C语言程序如下:

#include <iostream>



int main()
{
	int length;
	char letter[1000];
	scanf("%s", letter);
	length = strlen(letter);
	
	for (int i = 0;i < length;i++)                                  //删掉元音字母
	{
		if (letter[i] == 'a' || letter[i] == 'o' || letter[i] == 'y'
		 || letter[i] == 'e' || letter[i] == 'u' || letter[i] == 'i'
		 ||letter[i] == 'A' || letter[i] == 'O' || letter[i] == 'Y' 
		 || letter[i] == 'E' || letter[i] == 'U' || letter[i] == 'I')
		{
			letter[i] = '0';
		}
	}
	
	for (int i = 0;i < length;i++)                                  //大写换小写
	{
		if ((letter[i] >= 'A') && (letter[i] <= 'Z'))
		{
			letter[i] = letter[i] + 32;
		}
	}
	for (int i = 0;i < length;i++)                                 //输出“.”和字母
	{
		if (letter[i]!='0')
		{
			printf(".");
			printf("%c", letter[i]);
		}
	}

猜你喜欢

转载自blog.csdn.net/weixin_44003969/article/details/84874889