| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
代妈#include <iostream>
#include <cstring>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
struct wordt{
string word;
string upword;
}words[10000];
int numCnt, wordCnt, totalCnt;
bool isNum[10000];
int nums[10000];
void init(){
numCnt=0;
wordCnt=0;
totalCnt=0;
}
bool isaNum(string s){
int l = s.length();
for(int i = 0; i < l; i++){
if((s[i]>'9' || s[i]<'0') && s[i] != '-') return 0;
}
return 1;
}
char up(char c){
if(c>='a' && c<='z') return c-'a'+'A';
return c;
}
string up(string s){
string res;
int l = s.length();
for(int i = 0; i < l; i++){
res += up(s[i]);
}
return res;
}
bool cmp(const wordt& s1, const wordt& s2){
return strcmp(s1.upword.c_str(), s2.upword.c_str())==-1;
}
void parse(string s){
int l = s.length();
int start = 0;
for(int i = 0; i < l; i++){
if(s[i] == ',' || s[i] == '.'){
string xc = s.substr(start, i-start);
if(xc[0] == ' '){
xc = xc.substr(1);
}
if(isaNum(xc)){
isNum[totalCnt] = 1;
nums[numCnt] = atoi(xc.c_str());
numCnt++;
}
else{
isNum[totalCnt] = 0;
words[wordCnt].word = xc;
words[wordCnt].upword = up(xc);
wordCnt++;
}
start = i+1;
totalCnt++;
}
}
}
int main() {
string s;
while(1){
getline(cin ,s);
if(s[0]=='.')break;
init();
parse(s);
sort(words, words+wordCnt, cmp);
sort(nums, nums+numCnt);
int nword = 0, nnum = 0;
for(int i = 0; i < totalCnt; i++){
if(isNum[i]){
printf("%d", nums[nnum]);
nnum++;
}
else{
printf("%s", words[nword].word.c_str());
nword++;
}
printf("%s", i==totalCnt-1? ".\n": ", ");
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator