游客 Signup | Login
中文 | En

3091 - 2000年秋浙江省计算机等级考试二级C 编程题(2)

编制函数del_char

函数原型为 void del_char(char *,char),函数的功能是删除a指向的字符串中值为ch的字符,例如从字符串"AscADef"中删除'A'后,字符串为"scDef"。

Input

需要删除的字符ch

需要处理的字符串

Output

处理后的字符串

Examples

Input

A
AscADef

Output

scDef

Solution C

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <malloc.h>

void del_char(char *S,char D)
{
	char a[100];
	char *p;
	while (p=strchr(S,D))
	{
		strcpy(a,p+1);
		strcpy(p,a);
	}
}

int main()
{
	char ch,st[100];
	scanf ("%c",&ch);
	getchar();
	gets(st);
	del_char(st,ch);
	printf ("%s\n",st);
	return 0;
}

Solution C++

#include <stdio.h>
#include <string.h>
void del_char(char *s,char c)
{
 int i;
 char temp[256];
    strcpy(temp,s);
 for(i=0;i<strlen(temp);i++)
   {
      if (temp[i]!=c)
        *s++=temp[i];
   }
      
      *s='\0';
}
int main()
{
 char c,s[256];
 scanf("%c%s",&c,s);
 del_char(s,c);
 puts(s);
 return 0;
 
}
 
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题