zoukankan      html  css  js  c++  java
  • hdu 4550

    c:

    #include<stdio.h>
    #include<string.h>
    #define N  300
    int f[N];
    char s[N];
    int main() {
    int t,m,i,front,tear,j;
    char min;
    scanf("%d",&t);
    while(t--) {
    scanf("%s",s);
    memset(f,0,sizeof(f));
    m=strlen(s);
    front=tear=m;
    f[front]=s[0]-'0';
    min='9';
    for(i=0;s[i];i++)
    if(min>=s[i]&&s[i]!='0')  {
    min=s[i];
    j=i;
    }
    for(i=1;s[i];i++) {
    if(i==j)
    f[--tear]=s[i]-'0';
    else
    if(i>j)
    f[++front]=s[i]-'0';
    else
    if(i<j) {
    if(s[i]-'0'>f[tear])
    f[++front]=s[i]-'0';
    else
    f[--tear]=s[i]-'0';
    }
    }
    for(i=tear;i<=front;i++)
    printf("%d",f[i]);
    printf(" ");
    }
    return 0;
    }

    c++

    #include<cstring>  
    #include<iostream>
    #include<string>  
    using namespace std;  
    #define N 1010  
    char s[N];  
    int main(){  
        int T,i;
    char m='9';  
        string a;  
        scanf("%d",&T);  
        while(T--){  
        scanf("%s",s);  
        a=s[0];  
        int j=0;  
        for(i=0;s[i];i++){  
            if(s[i]!='0'){//找到非0最小的数  
                if(m>=s[i])m=s[j=i];  
            }  
        }  
            for(i=1;s[i];i++){  
                if(i==j)a=s[i]+a;  
                else if(i>j){  
                    a+=s[i];  
                }else if(i<j){  
                    if(s[i]>a[0])a+=s[i];  
                    else a=s[i]+a;  
                }  
            }  
            cout<<a<<endl;  
        }  
    return 0;  
    }  

  • 相关阅读:
    二叉堆(最小堆, 最大堆)介绍与实现
    C++ 用变量定义数组
    C++ 用变量定义数组
    053185
    053184
    053183
    053182
    053181
    053180
    oracle prior
  • 原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410830.html
Copyright © 2011-2022 走看看