String Detection One

Source: Internet
Author: User

Input: A set of integers greater than or equal to 0, regardless of illegal input, separated by "," between each integer, the total length of the input character is less than or equal to 100.

Output: According to the order from large to small, if there is continuous in the middle, only output the maximum and minimum value, the input of the various whole is not the same, do not consider the same situation. Separate integers with ",".

Cases:

Input: 1,4,7,2,5,8,9,11

Output: 11,9,7,5,4,2,1

1#include <stdio.h>2#include <stdlib.h>3#include <iostream>4#include <math.h>5#include <vector>6 intMain ()7 {8     Char*input = (Char*)malloc( -*sizeof(Char));9memset (Input,0,sizeof(input));Tenscanf"%s", input); Onestd::vector<int>Input_number; A      while((*input >='0') && (*input <='9') && (*input!=' /')) -     { -         if(*input!=',') the         { -             Charstr[5] =" /"; -             inti =0; -              while((*input! =',') && (*input!=' /')) +             { -str[i++] = *input; +input++; A             } at             if(strlen (str) >1) -             { - input_number.push_back (atoi (str)); -             } -             Else -             { inInput_number.push_back (* (* (input-1) -'0')); -             } to         } +input++; -     } the     intCount =0; *      for(std::vector<int>::iterator iter_out = Input_number.begin (); Iter_out! = Input_number.end (); iter_out++,count++) $     {Panax Notoginseng          for(std::vector<int>::iterator iter_in = Input_number.begin (); Iter_in! = Input_number.end ()-1-Count; iter_in++) -         { the             if((*ITER_IN) < (* (iter_in+1))) +             { A                 inttmp; thetmp=*iter_in; +*iter_in = * (iter_in +1); -* (iter_in +1) =tmp; $             } $         } -     } -      for(std::vector<int>::iterator iter = Input_number.begin (); ITER < Input_number.end ()-2;) the     { -         intFlag = ((*iter) +* (iter+2))-2* (* (iter+1));Wuyi         if(!flag) the         { -Iter=input_number.erase (iter+1); Wu         } -         Else About         { $iter++; -         } -     } -      for(std::vector<int>::iterator iter = Input_number.begin (); Iter! = Input_number.end ()-1; iter++) A     { +printf"%d,", *iter); the     } -std::vector<int>::iterator iter = Input_number.end ()-1; $printf"%d\n",*iter); the GetChar (); the GetChar (); the     return 0; the}

String Detection One

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.