Sort of acm_ Kai (string)

Source: Internet
Author: User

Sort of Kai time limit:2000/1000ms (java/others) problem Description:
Naughty kai like sorting, get everything to order. Now he felt that a single increment of descending order had been unable to satisfy him, so he was going to develop a new collation, the following rule: given a string of not more than 100, including uppercase letters, small letters, numbers and other English punctuation marks (including spaces, but no carriage returns), if it is uppercase, In descending order from Z to a, in case of lowercase letters or numbers, according to the rows from A to Z or from 0 to 9来, the other characters remain the same as the character types that correspond to each position after sorting. If it is "M105cpiccaz" before sorting, it is "Z015ACMICPC" after sorting.
Input:
The input includes multiple sets of data, the first behavior of each group of data is an integer n (1<=n<=100), which represents the length of the string, followed by a line of strings.
Output:
For each set of data, the output is sorted after the result.
Sample Input:
11m105cpiccaz18#include <STDio.H>
Sample Output:
Z015acmicpc#tdseiln <IHDou.C>
Problem-Solving ideas: simple string processing, the uppercase letter, lowercase letters, the numbers are sorted in order to fill in the corresponding type of position, and then output a whole string of results, water over!
AC Code:
1#include <bits/stdc++.h>2 using namespacestd;3 Const intmaxn= the;4 CharIR[MAXN],IU[MAXN],ID[MAXN],STR[MAXN],OBJ[MAXN];5 intKr,ku,kd,n;6 intMain () {7      while(cin>>N) {8GetChar (); gets (str); kr=ku=kd=0; memset (obj,' /',sizeof(obj));9          for(intI=0; str[i]!=' /';++i) {Ten             if(Islower (Str[i])) ir[kr++]=Str[i]; //ir array holds lowercase letters  One             if(Isupper (Str[i])) iu[ku++]=Str[i]; //iu Array holds uppercase letters  A             if(IsDigit (Str[i])) id[kd++]=Str[i]; //id Array holds numbers  -         } -Sort (IR,IR+KR); sort (iu,iu+ku); sort (ID,ID+KD); kr=kd=0; the          for(intI=0; str[i]!=' /';++i) { -             if(Islower (Str[i])) obj[i]=ir[kr++]; -             Else if(Isupper (Str[i])) obj[i]=iu[--ku]; -             Else if(IsDigit (Str[i])) obj[i]=id[kd++]; +             Elseobj[i]=Str[i]; -         } +cout<<obj<<Endl; A     } at     return 0; -}

Sort of acm_ Kai (string)

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.