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. B2761 [JLOI2011]不重复数字 离散化

    就是一道离散化的裸题,但是在写的时候遇到了一些不可描述的问题,但是还是很顺利的. 题干: Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 ,其中2 ...

  2. null, undefined,"",0,false是什么关系?

    null本质上和0,"",false是一类东西,它们都表示一种数据类型的非值.正如0表示数字类型的非值,""表示字符类型的非值一样,null表示完全空的对象,即 ...

  3. AcWing算法基础1.5

    前缀和与差分 两个内容都比较少,就放一起写了 设数组 a 的前 n 项为a1 , a2 , a3 ... an 前缀和数组就是每一项是a数组的前i项和,比如前缀和数组res,res[ 1 ] = a[ ...

  4. Akka源码分析-Persistence

    在学习akka过程中,我们了解了它的监督机制,会发现actor非常可靠,可以自动的恢复.但akka框架只会简单的创建新的actor,然后调用对应的生命周期函数,如果actor有状态需要回复,我们需要h ...

  5. Vue解决移动端localhost无数据问题

    正常web端调用后台接口时使用localhost或者ip都能访问后台数据,但是在移动端上使用localhost却无法访问后台数据 这时候需要把localhost改成ip就可以在移动端上访问后台数据了

  6. mysql中判断记录是否存在方法

    以下这个方法是我推荐的. sql语句:select 1 from tablename where col = col limit 1; 然后读取语句执行所影响的行数. 当然这里limit 1很重要.这 ...

  7. 点击文字弹出一个DIV层窗口代码 【或FORM表单 并且获取点击按钮的ID值】

    点击不同按钮咨询不同的 专家 <?php for($i=1;$i<5;$i++){ $uid=$i; //用户ID ?> <a class="a_click" ...

  8. mybatis or

    这两天项目用到mybatis,碰到and or的联合查询,语句像这样的 select * from table where xxx = "xxx" and (xx1="x ...

  9. 在Windows2003安装配置Bitvise SSH Server后,不能使用软件内建立的用户登录!

    Google:  I can only log in with an administrator account - attempting to log in with a regular accou ...

  10. js常用操作~~~~将持续更新

    1.替换多个模板变量 var s="my javascript is very poor,who can help me?" var reg=/(\w*)my(.*)is(.*)c ...