hdoj 1106 排序 【水題】,hdoj1106

來源:互聯網
上載者:User

hdoj 1106 排序 【水題】,hdoj1106

排序Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35499    Accepted Submission(s): 10042

Problem Description輸入一行數字,如果我們把這行數字中的‘5’都看成空格,那麼就得到一行用空格分割的若干非負整數(可能有些整數以‘0’開頭,這些頭部的‘0’應該被忽略掉,除非這個整數就是由若干個‘0’組成的,這時這個整數就是0)。

你的任務是:對這些分割得到的整數,依從小到大的順序排序輸出。

 
Input輸入包含多組測試案例,每組輸入資料只有一行數字(數字之間沒有空格),這行數位長度不大於1000。  

輸入資料保證:分割得到的非負整數不會大於100000000;輸入資料不可能全由‘5’組成。
 
Output對於每個測試案例,輸出分割得到的整數排序的結果,相鄰的兩個整數之間用一個空格分開,每組輸出佔一行。
 
Sample Input
0051231232050775
 
Sample Output
0 77 12312320

睡前一水

代碼:

#include <stdio.h>#include <string.h>#include <algorithm>#define M 1005using std::sort;int s[M];char str[M];int main(){while(gets(str)){int len, tot = 0, i;len = strlen(str);i = 0;//while(str[i] == '0') i++;while(str[i] == '5') i++;int temp = 0;while(i < len){if(str[i] == '5'){i++;while(i<len&&str[i] == '5') i++;s[tot++] = temp; temp = 0;}else{temp = temp*10+str[i]-'0'; i++;}}if(str[len-1] != '5') s[tot++] = temp;sort(s, s+tot);printf("%d", s[0]);for(i = 1; i < tot; i ++) printf(" %d", s[i]);printf("\n");}return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.