左嘉


私信TA

用户名:zuojia

访问量:82795

签 名:

Jz

等  级
排  名 4
经  验 33615
参赛次数 226
文章发表 72
年  龄 40
在职情况 在职
学  校 北京理工大学
专  业

  自我简介:

解题思路:这里输入字符串中的字符,一般是ASCII字符,从0到255,范围不大;采用查表v[256]的方法,例如'a'是元音字母,那么v['a']就设置为非零,if(v['a'])即可找到'a'并存入另一用来输出的字符串。

注意事项:这里的元音字母可以不包括相应的大写字母。

参考代码:

#include<stdio.h>
#include<string.h>
#define N 1000
int main(){
	char *vowel(char *str1,const char *str2);
	char s1[N],s2[N];
	gets(s2);//输入字符串
	puts(vowel(s1,s2));//找到元音字母并输出
	return 0;
}
char *vowel(char *str1,const char *str2){
	int i,j,len;
	char v[256];//ASCII码表
	memset(v,'\0',sizeof(v));//初始化
	v['a']=v['e']=v['i']=v['o']=v['u']=' ';//特殊位置为非零
	len=strlen(str2);
	for(i=0,j=0;i<len;i++)
		if(v[str2[i]])//用str2[i]查表找到元音字母
			str1[j++]=str2[i];//存入另一字符串
	str1[j]='\0';//字符串结尾
	return str1;
}


 

0.0分

42 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

int main(int argc, char *argv[]){
	std::string a,b;
	std::cin>>a;
	for(std::string::iterator s = a.begin(); s != a.end(); ++s){
		if(*s=='a' || *s=='e' || *s=='i' || *s=='o' || *s=='u'){
			b+=*s;
		}
	}
	std::cout<<b;
}

几行代码就能解决的,它不香吗?
2020-02-25 15:44:09
#include <stdio.h>
 
void trans(char ch1[],char ch2[])
{
	int i,j;
	for(i=0,j=0;i!='\0';i++)
	{
		if((ch1[i]=='a')||(ch1[i]=='e')||(ch1[i]=='i')||(ch1[i]=='o')||(ch1[i]=='u'))
		{
			ch2[j]=ch1[i];
			j++;
		}
		ch2[j]='\0';
	}


}
int main()
{
	void cpy(char ch1[],char ch2[]);
	char ch1[100],ch2[100];
	gets(ch1); 
	trans(ch1,ch2);
	printf("%s",ch2);
	return 0;
}

有同学知道吗??我这个为什么输出是乱码??????????
2020-02-13 00:51:26
为社么错误50%?

#include <stdio.h>
int str(char a[20],char b[20])
{
	int i,j;
	for(i=0,j=0;i<20;i++)
	{
		if(a[i]=='a' || a[i]=='e' || a[i]=='i' || a[i]=='o' || a[i]=='u')
	    {
    		b[j]=a[i];
    		j++;
    	}
	if(a[i]=='\0')break;
	}
}
int main(int argc, char *argv[])
{
	char a[20],b[20]={0};
	scanf("%s",a);
	str(a,b);
	printf("%s",b);
	return 0;
}
2020-02-12 20:23:58
#include<iostream>
#include"stdio.h"
#include<cstdio>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;

int main()
{
	char a[100],b[100],s;
	int n=0,m=0;
	s=getchar();
	while(s!='\n')
	{    a[n]=s;
	if(a[n]=='a'||a[n]=='e'||a[n]=='i'||a[n]=='o'||a[n]=='u')
    	{	b[m++]=a[n];}
	s=getchar();
		n++;	}
	for(int i=0;i<m;i++)
	{
		printf("%c",b[i]);
	}
	return 0;
}

为什么dev可以,这里提示运行错误啊
2020-02-10 22:55:29
#include<stdio.h>
#include<string.h>
int main()
{
	char a[100] = "\0",c[100] = "\0";
	int b;
	int j = 0;
	fgets(a,99,stdin);
	b = strlen(a);
	for (int i = 0; i < b; i++)
		if (a[i] == 65 || a[i] == 69 || a[i] == 73 || a[i] == 79 || a[i] == 85 || a[i] == 97 || a[i] == 101 || a[i] == 105 || a[i] == 111 || a[i] == 117)
		{
			c[j] = a[i];
			j++;
		}
	printf("%s",c);
	return 0;
}
不足之处请指教
2020-02-04 00:39:07
#include<stdio.h>
#include<string.h>
#define max (c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
#define min (c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
int main()
{
	char a[100],b[100],c='m';
	int max,min;
	int i=0,m,j=0;
	gets(a);
	m=strlen(a);
	for(i=0;i<m;i++)
	{
		c=a[i];
		if(max||min)
			b[j++]=a[i];
	}
	b[j]='\0';
	puts(b);
	return 0;
}
为什么在vc++6.0上可以,在这里就不行啊?

求解答
2020-02-03 16:36:34
不知道为啥这个错%50,有大佬帮忙优化一下么??
#include<iostream>

#include<string.h>
using namespace std;


int main()
{
char  c;
int i,n;
char a[5],b[5];

for (int i=0;i<5;i++)
{

cin>>a[i];
}


for(int j=0,m=0;j<5;j++,m++)
{ 
if(a[j]=='a'||a[j]=='i'||a[j]=='o'||a[j]=='e'||a[j]=='u')
  {
   b[m]=a[j];
  } 
  
}

n=strlen(b);

for(int i=0;i<5;i++)
if(b[i]!=NULL)
cout<<b[i];

 return 0;
}
2019-12-16 13:56:14
#include<stdio.h>
#include<stdlib.h>
int tremp(int* arr, int* b);

int main(void)
{
	
	int* arry = malloc(50 * sizeof(int));
	int* b2 = malloc(50 * sizeof(int));
	tremp(arry[49], b2[49]);
	return 0;
}

int tremp(int* arr, int* b)
{
	int m = 0;
	int n = 0;
	while (arr!='/t')
	{
		arr[m] = getchar();
		m++;
	}
	for (int j = 0; j < m; j++)
	{
		if (arr[j] == 'a' || arr[j] == 'e' || arr[j] == 'i' || arr[j] == 'o' || arr[j] == 'u')
		{
			b[n] = arr[j];
			n++;
		}
	}
	for (int i = 0; i < n; i++)
	{
		printf("%d", b[i]);
	}
}

有大佬能告诉我为甚么提示数组越界了吗,应该怎么样进行改动
2019-10-22 16:55:09