華為機試験問題——文字列操作


/*
    :  
             、                   ,      。 
      :  
void my_string(char* input, char* output) 
【  】  char* input,       【  】  char* output,        【  】    
    
  :input = “A*(BC&De+_fg/*”   :output = “ABCDefg”   :input = “aB+_9”   :output = “aB9”
*/
#include <iostream>
using namespace std;
void my_string(char *input,char *output)
{
	int i;
	int j;
	j=0;
	for(i=0;input[i]!='\0';i++)
		if(isalnum(input[i])!=0)
			output[j++]=input[i];
	output[j]='\0';
}

int main(void)
{
	char *input="A*(BC&De+_fg/*";
	char *output=new char[100];
	my_string(input,output);
	cout<<output<<endl;
	input="aB+_9";
	my_string(input,output);
	cout<<output<<endl;
	system("pause");
	return 0;
}