Huawei Machine Test-integer reverse order and go to weight

Source: Internet
Author: User

Enter an integer, such as 12336544, or 1750, and then start the output from the last one, and finally if it is 0, then not output, the output number is not a repeating number, so the above output is 456321 and 571. If it is negative, such as input-175, output-571.

#include <iostream> #include <string>using namespace std;//Reverse char * revs (char *s) {int J = strlen (s)-1; int I=0;char T;while (i<j) {t = s[i];s[i++]=s[j];s[j--]=t;} return s;}       void process (const char *PINPUTSTR, long Linputlen, char *poutputstr) {bool Flag[10] = {0};    Int j = 0;int flag_0=0;          for (int i = 0;i < linputlen;i++) {if (Flag[pinputstr[i]-' 0 '] = = 0)//pinputstr[i] appears for the first time.  {if (Pinputstr[i]-' 0 ' ==0 && flag_0==0); else{flag_0=1;poutputstr[j++] = Pinputstr[i]; flag[pinputstr[i]-' 0 '] =  1;  }}} poutputstr[j]= ' + '; for (i=0;i<j;i++) Cout<<poutputstr[i];cout<<endl<<endl;} int main () {char *input=new char[100];char *output=new char[100];char *s=new char[100];char *ss;int k=0;while (cin> >input) {k=0;if (input[0]== '-') {cout<< "-"; for (int i=1;i<strlen (input); i++) s[k++]=input[i];s[k]= ' + '; Ss=revs (s);p rocess (Ss,strlen (ss), output);} Else{ss=revs (Input);p rocess (Ss,strlen (ss), Output);}} DeletE input;delete output;delete S;return 0;} 


Huawei Machine Test-integer reverse order and go to weight

Related Article

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.