OJ Test topic--Delete duplicate characters

Source: Internet
Author: User






Topic title:


    • Remove repeating characters

    • Given a string, all the characters in the string are removed, the remaining characters are preserved, and the processed string is output. You need to guarantee the order in which characters appear and are case-sensitive.


Detailed Description:


    • Interface description


Prototype:



int GetResult (const char *input, char *output)



Input parameters:



The string entered by input



Output parameters (consider whether the memory area pointed to by the pointer is valid):



string of output outputs



return value:



0 successes



-1 Failures and exceptions



Example:



Input: AB a DC Bad , the characters in the red part of the word have already appeared before.



Then: Output ABDC, return 0.




For the subject, very simple, but want to pass almost impossible, this is the usual problem of programming habits, especially pay attention to the judgment of the null pointer! The following code is passed:





int GetResult (const char *input, char *output) {if (input = = NULL | | output = = NULL) {return-1;} int hash[1000] = {0};int i = 0;while (*input! = ') {hash[(*input-' 0 ')]++;if (hash[(*input-' 0 ')] = = 1) {output[i++] = *i Nput;} input++;} Output[i] = ' + ';    return 0;}












OJ Test topic--Delete duplicate characters


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.