Document directory
- Problem Description
- Input
- Output
- Sample Input
- Sample Output
Sort Time Limit: 2000/1000 ms (Java/Other) Memory Limit: 65536/32768 K (Java/Other) Total Submission (s): 49 Accepted Submission (s): 17 Font: times New Roman | Verdana | GeorgiaFont Size: Regular → Problem Description enter a number in a row. If we regard '5' in this row as a space, then several non-negative integers (some integers may start with '0' and the '0' of these headers should be ignored, unless this integer is composed of several '0', then this integer is 0 ).
Your task is to sort the generated integers in ascending order.
The Input contains multiple groups of test cases. Each group of Input data has only one row of numbers (no space between numbers), and the length of this line of numbers is not greater than 1000.
Input data guarantee: The calculated non-negative integer is not greater than 100000000, and the input data cannot all be composed of '5. For each test case, Output results are sorted by integers. Two Adjacent integers are separated by a space. Each group occupies one row. Sample Input
0051231232050775
Sample Output
0 77 12312320
Through joint efforts with roommates, the final result is...
import java.util.ArrayList;import java.util.Collections;import java.util.Iterator;import java.util.Scanner;public class abc {public static void main(String[] args) {Scanner cin = new Scanner(System.in);while(cin.hasNext()){ArrayList list =new ArrayList();String st =cin.next();String[] str=st.split("[5]");int p=0;int []arr=new int[str.length];for(int i=0;i<str.length;i++){if(!str[i].equals("")){list.add(Integer.valueOf(str[i]));}}Collections.sort(list);int i=0;for(;i<list.size();i++){System.out.print(i!=0?" "+list.get(i):list.get(i));}System.out.println();}}}
C code:
#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ char a[10000], b[100]; int i, j, t, len, temp, c[10000]; memset(a, 0, sizeof(a)); while(scanf("%s", a) != EOF) { getchar(); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); len = strlen(a); for(i=j=t=0; i<len; ++i) { if(a[i] == '5') { if(!i) continue; else if(j != 0) { c[t++]=atoi(b); memset(b, 0, sizeof(b)); j = 0; } } else b[j++]=a[i]; } if(a[i] != 5) { if(j != 0) { c[t++]=atoi(b); memset(b, 0, sizeof(b)); j = 0; } } for(i=1; i<t; ++i) { len = 0; for(j=0; j<t-i; ++j) { if(c[j]>c[j+1]) { len = 1; temp = c[j]; c[j] = c[j+1]; c[j+1] = temp; } } if(!len) break; } for(i=0; i<t; ++i) if(!i) printf("%d", c[i]); else printf(" %d", c[i]); printf("\n"); memset(a, 0, sizeof(a)); } return 0;}