CodeForces-118A——Vjudge String Task

String Task CodeForces

- 118A:

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

Input
tour
Output
.t.r

Input
Codeforces
Output
.c.d.f.r.c.s

Input
aBAcAba
Output
.b.c.b

问题简述:输入一串仅有英文字母的连续的字符串,把大写变小写,删去每个元音aoyeui,在每个辅音前加点‘.’。
程序1说明:获取字符串后,将字符一个个输入,每输入一个字符过一遍循环,字符若大写,则改为小写,再删除元音,后输出“.%c”,避免了繁琐的数组运算,内存占用很低。

AC通过的代码如下(基于c语言):

#include<stdio.h>

int main()
{
	char a;
	for(scanf("%c",&a);a!='\n';scanf("%c",&a))
	{
		if(a>=65 && a<=90) a+=32;
		if(a!='a'&&a!='o'&&a!='y'&&a!='e'&&a!='u'&&a!='i')
		   {
		   		printf(".%c",a);
		   }
	}
}

未通过的代码(Wrong answer on test 34 错误原因未知)如下

#include<stdio.h>

int main()
{
	int i,j;
	char str[100]={0};
	char str2[200]={0};
	scanf("%s",str);
	for(i=0;str[i]!=NULL;i++)
	{
		if(str[i]=='A'||str[i]=='a'||str[i]=='O'||str[i]=='o'||\
		   str[i]=='Y'||str[i]=='y'||str[i]=='E'||str[i]=='e'||\
		   str[i]=='U'||str[i]=='u'||str[i]=='I'||str[i]=='i')
		{
			for(j=i;str[j]!=NULL;j++)
			{
				str[j]=str[j+1];
			}
			i--;
			str[j]=NULL;
		}
		if(str[i]>=65 && str[i]<=90)
		str[i]+=32;
	}
	for(i=0;str[i]!=NULL;i++)
	{
		str2[2*i+1]=str[i];
		str2[2*i]='.';
	}
	if(str2[0]=='\0')
	{
		return 0;
	}
	for(i=0;str2[i]!=NULL;i++)
	{
		printf("%c",str2[i]);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43887417/article/details/84866188