題目描述:Lily上課時使用字母數字圖片教小朋友們學習英語單詞,每次都需要把這些圖片按照大小(ASCII碼值從小到大)排列收好。請大家給Lily幫忙解決。
輸入描述:Lily使用的圖片包括"A"到"Z"、"a"到"z"、"0"到"9"。輸入字母或數字個數不超過1024。
輸出描述:Lily的所有圖片按照從小到大的順序輸出
輸入例子:Ihave1nose2hands10fingers
輸出例子:0112Iaadeeefghhinnnorsssv
算法實現:
#include<iostream>#include<string>#include<vector>using namespace std;/************************************************ * Author: 趙志乾 * Date: 2017-2-17 * Declaration: All Rigths Reserved !!! ***********************************************/ int main(){ string instr; getline(cin,instr); vector<int>buck(128,0); for(int i=0;i<instr.length();i++) { buck[instr[i]]++; } string ret=instr; int index=0; for(int i=0;i<128;i++) { while(buck[i]>0) { ret[index++]=i; buck[i]--; } } cout<<ret<<endl; return 0;}
新聞熱點
疑難解答
圖片精選