一期作业第一题

题目:
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.
翻译版:
皮塔开始参加程序设计课程。在第一节课上,他的任务是编写一个简单的程序。程序应该执行以下操作:在给定的字符串中,它由大写字母和小写字母组成:

删除所有元音,

在每个辅音之前插入一个字符“。”

用相应的小写字母替换所有大写辅音。

元音字母是“A”、“O”、“Y”、“E”、“u”、“I”,其余都是辅音。程序的输入正好是一个字符串,它应该以单个字符串的形式返回输出,在程序处理初始字符串之后得到结果。

帮助皮塔应付这个简单的任务。

输入

第一行表示Petya程序的输入字符串。这个字符串只由大写字母和小写字母组成,长度从1到100,包含。

产量

打印得到的字符串。保证此字符串不是空的。

#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
	char old[220];
	cin >> old;
	//int v;
	//int over;
	//for (v = 0; v <= 100; v++)
	//{
	//	if (old[v] == '\0' || old[v] == '\n')
	//	{
	//		over = v-1;
	//	}
	//}
	//for (v = 0; v <= over; v++)
	//{
	//	if (old[v] >= 97 && old[v] <= 122);
	//	else if (old[v] >= 65 && old[v] <= 90);
	//	else
	//	{
	//		return 0;
	//	}
	//}
	int i;
	int j;
	int k;
	for (i = 0; i <= 219; i++)            //全部大写变小写
	{
		if (old[i] <= 90)
		{
			if (old[i] == '\0' || old[i] == '\n')
			{
				continue;
			}
			old[i] = old[i] + 32;
		}
	}
	for (j = 100; j >= 0; j--)            //全部元音都删除
			{
				if(old[j] == 'a'|| old[j] == 'e'|| old[j] == 'i'|| old[j] == 'o'|| old[j] == 'u'|| old[j] == 'y')
				{
					if (j == 100)
					{
						old[j] = '\0';
					}
					k = j;
					for (; k <= 99; k++)
					{
						old[k] = old[k + 1];
					}
				}
			}
	int p;
	int m;
	int q;
	for (p = 219; p >= 0; p--)      //加小点
	{
		if (old[p] >= 97 && old[p] <= 122)
		{
			m = p;
			for (q = 218; q >= m; q--)
			{
				old[q + 1] = old[q];
				old[q] = '.';
			}
		}
	}
	cout << old << endl;
	return 0;
}

先全部变小写,再删除元音,再加入所需的 ‘。’
用了一些for循环实现这个结果。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值