zoukankan      html  css  js  c++  java
  • pat每日刷题计划--day69

    PAT B1023 组个最小数

    非常简单的贪心,注意输入数据范围,保证了有非零数字,但是同时最多可以有50个数,longlong也会爆,一定要直接输出

    其实ans数组可以不用,输出就行

    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    using namespace std;
    int main()
    {
        long long num=0;
        int temp[15];
        for(int i=0;i<=9;i++)
            scanf("%d",&temp[i]);
        int ans[55];
        int a=1;
        while(temp[a]==0)
            a++;
        ans[0]=a;
        temp[a]--;
        int now=1;
        a=0;
        while(a<10)
        {
            while(temp[a]>0)
            {
                ans[now++]=a;
                temp[a]--;
            }
            a++;
        }
        for(int i=0;i<=now-1;i++)
        {
            cout<<ans[i];
            //num*=10;
            //num+=ans[i];
        }
        //printf("%lld",num);
        return 0;
    }
    View Code
    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    using namespace std;
    int main()
    {
        long long num=0;
        int temp[15];
        for(int i=0;i<=9;i++)
            scanf("%d",&temp[i]);
        int ans[55];
        int a=1;
        while(temp[a]==0)
            a++;
        cout<<a;
        temp[a]--;
        a=0;
        while(a<10)
        {
            while(temp[a]>0)
            {
                cout<<a;
                temp[a]--;
            }
            a++;
        }
        return 0;
    }
    终结
    时间才能证明一切,选好了就尽力去做吧!
  • 相关阅读:
    [LintCode] 最长上升子序列
    [LintCode] 最长公共前缀
    [LintCode] A + B 问题
    [hihoCoder] 拓扑排序·一
    [LintCode] 拓扑排序
    [LintCode] 第k大元素
    [LintCode] 最小路径和
    [LeetCode] Factorial Trailing Zeros
    [LintCode] 尾部的零
    [LeetCode] Length of Last Word
  • 原文地址:https://www.cnblogs.com/tingxilin/p/12239204.html
Copyright © 2011-2022 走看看