HDU 1106 排序

用了两个库函数,一下子把题目简化了很多!很多情况全部使用,上代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(){
    char s[1005];
    int ans[1005];
    char *a;
    int j;


   while(cin>>s){  //输入字符串
    int tmp = 0;
    a=strtok(s,"5"); //分割字符串
    while(a){        //判断返回是否为NULL

        ans[tmp++]=atoi(a);  //把字符型数字转换成整形!不用在用乘加法了。

        a=strtok(NULL,"5");  //换下一个分割的标记串,如果有返回ture,否则false
    }

    sort(ans,ans+tmp);  //把转换的整形排序了
    for(j=0;j<tmp;j++)
        if(j!=tmp-1)
    cout<<ans[j]<<" ";
    else
        cout<<ans[j];   //OJ常见格式,最后一个分割串没空格
    cout<<endl;
   }

   }



原文地址:https://www.cnblogs.com/zhangmingzhao/p/7256474.html