[Huawei Machine Test exercises]15. Delete duplicate characters/delete duplicate strings

Source: Internet
Author: User

Topic

题目标题:删除重复字符给定一个字符串,将字符串中所有和前面重复多余的字符删除,其余字符保留,输出处理后的字符串。需要保证字符出现的先后顺序,并且区分大小写。详细描述:接口说明原型:int GetResult(const char *input, char *output)输入参数:     input     输入的字符串输出参数(需考虑指针指向的内存区域是否有效):    output    输出的字符串返回值:        0         成功         -1        失败及异常举例:输入: abadcbad,那么该单词中红色部分的字符在前面已经出现过。则:输出abdc,返回0。知识点:     工程环境请使用VS2005题目来源:    软件训练营 维护人:     d00191780 练习阶段:    

Code

/*---------------------------------------* Date: 2015-06-30* sjf0115* title: Delete Duplicate character/delete duplicate String * Source: Huawei on-Machine----------------- ------------------------*/#include <stdio.h>#include <string.h>/*description Given a string, all the characters in the string are deleted, the remaining characters are preserved, and the processed string is output. The order in which characters appear must be guaranteed.          Prototype int GetResult (const char *input, char *output) input Param inputs string output Param Output string return Value 0 Success-1 failure and exception */intGetResult (Const Char*input,Char*output) {if(input = = NULL | | output = = NULL) {return-1; }//if    intSize =strlen(input);//Statistics number of characters appearing    inthash[ the] = {0};intindex =0; for(inti =0; i < size;++i) {//Before judging whether or not there have been        if(Hash[input[i]] = =0) {output[index++] = Input[i]; }//if++hash[input[i]]; }//forOutput[index] =' + ';return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[Huawei Machine Test exercises]15. Delete duplicate characters/delete duplicate strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.