POJ1520

/*vecotr_change POJ1520*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <cstring>
#define INT_MIN 0x80000000
#define INT_MAX 0xffffffff
#define N 100
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN(a,b) (a)<(b)?(a):(b)
#define LL long long
#define debug(x) cout<<#x<<":"<<(x)<<endl;
using namespace std;
string w[N];
string alp[N];
int num[N];
int flag[N];
int sort_num;
int cnt1, cnt2;
int atoi( string a )
{
    int ans = 0;
    int i = 0;
    bool f = false;
    if( a[0] == '-' )
    {
        i++;
        f = true;
    }
    while( i < a.length() )
    {
        ans = ans*10 + a[i] - '0';
        i++;
    }
    if( f ) ans = -ans;
    return ans;
}
int is_alp( string a )
{
    if( a[0] >= 'A' && a[0]<='Z' || a[0] >='a' && a[0] <='z')
        return 1;
    else return 0;
}
int input()
{
    string str;
    int end_flag = 0;
    int i = 0;
    while( 1 )
    {
        cin >> str;
        int len = str.length() - 1;
        if( str[0] == '.' ) return 0;  //end_input
        if( str[len] == '.' ) end_flag = 1; //end
        str.erase(str.end()-1);
        w[i] = str;
        i++;
        if( end_flag ) break;
    }
    sort_num = i; // start from 1
    return 1;
}
string lowercase( string k )
{
    int i = 0;
    while( i < k.length() )
    {
        if( k[i] >= 'A' && k[i] <= 'Z') k[i] = k[i] + 'a' - 'A';
        i++;
    }
    return k;
}
int cmp(string a, string b)
{
    return lowercase(a) < lowercase(b);
}
void parition()
{
    cnt1 = 0, cnt2 = 0;
    for( int i=0; i<sort_num; i++)
    {
        if( is_alp(w[i]) )
        {
            alp[cnt1++] = w[i];
            flag[i] = 1;
        }
        else
        {
            num[cnt2++] = atoi( w[i] );
            flag[i] = 0;
        }
    }
}
void display()
{
    cnt1 = 0, cnt2 = 0;
    for( int i=0; i<sort_num; i++)
    {
        flag[i]?cout<<alp[cnt1++]:cout<<num[cnt2++];
        if( i < sort_num-1) cout<<", ";
        else cout<<"."<<endl;
    }
}
//15-2-13
int main() 
{
    //freopen("1.txt", "r", stdin);
    while( input() )
    {
        parition();
        sort(num, num+cnt2);
        sort(alp, alp+cnt1, cmp);
        display();
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值