[Huawei machine trial exercise questions] 15. Delete duplicate characters/delete duplicate strings, Huawei exercises

Source: Internet
Author: User

[Huawei machine trial exercise questions] 15. Delete duplicate characters/delete duplicate strings, Huawei exercises

Question

Title: delete duplicate characters. Given a string, remove all redundant characters in the string that have already been duplicated. Keep the remaining characters and output the processed string. Ensure the order in which the characters appear and are case sensitive. Description: interface prototype: int GetResult (const char * input, char * output) input parameter: String output parameter of input (whether the Pointer Points to the memory zone is valid ): output string return value: 0 success-1 failure and exception example: input: abadcbad, then the red part of the word has appeared before. Then: Output abdc, return 0. Knowledge Point: Use VS2005 for engineering environment Source: software training camp maintainer: d00191780 exercise stage: elementary

Code

/* ------------------------------------- * Date: 2015-06-30 * Author: SJF0115 * Subject: delete duplicate characters/delete duplicate strings * Source: Huawei computer license */# include <stdio. h> # include <string. h>/* Description specifies a string to delete all redundant characters in the string that have been repeated with the previous one. The remaining characters are retained and the processed strings are output. Ensure the order of characters. Prototype int GetResult (const char * input, char * output) input Param input string Output Param output string Return Value 0 success-1 failure and exception */int GetResult (const char * input, char * output) {if (input = NULL | output = NULL) {return-1;} // if int size = strlen (input ); // number of statistical characters: int hash [256] = {0}; int index = 0; for (int I = 0; I <size; ++ I) {// determine whether there has been an if (hash [input [I] = 0) {output [index ++] = input [I];} // if ++ hash [input [I];} // for output [index] = '\ 0'; return 0 ;}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.