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("\n");

}

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;  

}

hdu 4550的更多相关文章

  1. hdu 4550 卡片游戏 贪心

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4550 题意:有n(n <= 100)个0~9之间的卡片,从左往右将卡片放到之前的卡片最左边或者最 ...

  2. hdu 4550 卡片游戏

    http://acm.hdu.edu.cn/showproblem.php?pid=4550 贪心 #include <cstdio> #include <cstring> # ...

  3. hdu 4550 贪婪 思考题 权

    http://acm.hdu.edu.cn/showproblem.php?pid=4550 想了挺久,然后各种分类 最终AC,假设是现场,对自己没信心的话,预计还是要WA,,,,,,然后搜题解,发现 ...

  4. hdu 模拟 贪心 4550

    卡片游戏 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. windows下写的脚本,在linux下执行失败

    Windows中的换行符为CRLF, 即正则表达式的rn(ASCII码为13和10), 而Unix(或Linux)换行符为LF, 即正则表达式的n. 在Windows和Linux下协同工作的时候, 往 ...

  2. hibernate字段名和属性

    字段名和属性名相同 Annotation:默认为@Basic 注意:如果在成员属性没有加入任何注解,则默认在前面加入了@Basic Xml中不用写column 字段名和属性名不同 Annotation ...

  3. MVC web api 返回JSON的几种方式,Newtonsoft.Json序列化日期时间去T的几种方式。

    原文链接:https://www.muhanxue.com/essays/2015/01/8623699.html MVC web api 返回JSON的几种方式 1.在WebApiConfig的Re ...

  4. esp和ebp指针

    gdb调试的时候会出现esp和ebp这两个指针,而这两个指针为我们查看栈的情况提供了方便. 简单点说,esp指向栈顶,而ebp指向栈底.例如一段程序: #include <stdio.h> ...

  5. IE下元素设置百分比的问题

    场景:近两天在做一个控件,该控件是一个tab型的,并且该tab有可能是两个tab标签,也有可能是多个tab标签,为了能够适应这种动态需求, 在设置标签宽度的时候,直接用的最外层容器除以tab的个数,然 ...

  6. [转]linux之初识SELinux

    转自:http://www.linuxidc.com/Linux/2014-07/104447.htm 1.selinux的概述 selinux相信大家一定不会陌生,它的全称是内核级加强型防火墙.在服 ...

  7. webHttpBinding+wsHttpBinding+basicHttpBinding的区别 (转)

    1. webHttpBinding (web AJAX/JSON)2. wsHttpBinding (ASP.NET client) 3. basicHttpBinding (Silverlight) ...

  8. 个人作业——Alpha项目测试

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1/ 这个作业要求在哪里 https://edu.cnbl ...

  9. 初学layer

    canvas是支持图层layer渲染这种技术的,canvas默认就有一个layer,当我们平时调用canvas的各种drawXXX()方法时,其实是把所有的东西都绘制到canvas这个默认的layer ...

  10. elasticsearch——海量文档高性能索引系统

    elasticsearch elasticsearch是一个高性能高扩展性的索引系统,底层基于apache lucene. 可结合kibana工具进行可视化. 概念: index 索引: 类似SQL中 ...