1412091645-hd-ZOJ,

來源:互聯網
上載者:User

1412091645-hd-ZOJ,
ZOJTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1899    Accepted Submission(s): 1344

Problem Description讀入一個字串,字串中包含ZOJ三個字元,個數不一定相等,按ZOJ的順序輸出,當某個字元用完時,剩下的仍然按照ZOJ的順序輸出。 
Input題目包含多組用例,每組用例佔一行,包含ZOJ三個字元,當輸入“E”時表示輸入結束。
1<=length<=100。
 
Output對於每組輸入,請輸出一行,表示按照要求處理後的字串。
具體可見範例。 
Sample Input

ZZOOOJJJZZZZOOOOOJJJZOOOJJE
 
Sample Output
ZOJZOJOJZOJZOJZOJZOOZOJOJO
 解題思路        確定Z、O、J的數量。然後迴圈判斷,數量不為0就輸出,迴圈len次。代碼
#include<stdio.h>#include<string.h>char zoj[110];int main(){int len;int i,j,k;int numz,numo,numj;while(scanf("%s",zoj)&&strcmp("E",zoj)!=0){len=strlen(zoj);numz=numo=numj=0;for(i=0;i<len;i++){if(zoj[i]=='Z')    numz++;else if(zoj[i]=='O')    numo++;else    numj++;}while(len--){if(numz!=0)//數量不為0就輸出,為0就跳過 {printf("Z");numz--;}if(numo!=0){printf("O");numo--;}if(numj!=0){printf("J");numj--; }}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.