zoukankan      html  css  js  c++  java
  • HZNU 2154 ldh发奖金【字符串】

    题目链接

    http://acm.hznu.edu.cn/OJ/problem.php?id=2154

    思路

    先判断不能拆分的情况
    以为需要拆分成两个正整数
    所以我们可以知道
    只有个位的数字 是不能够拆分的
    还有 类似于 100 1000000

    这种 在每个数位上 只有一个非0数字的 整数 也是不能够拆分的

    然后要考虑如何拆分

    其实我们容易想到
    数位越高 那么这个数字 就会越大
    我们应该要尽量 只拆除一个 个位数字 其他数字 从大到小 排列 组成另一个全新的数字

    因为 每一位都是可以随意交换的

    这样做对答案的贡献就最大

    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    #include <limits>
    
    #define CLR(a) memset(a, 0, sizeof(a))
    #define pb push_back
    
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef pair <int, int> pii;
    typedef pair <ll, ll> pll;
    typedef pair<string, int> psi;
    typedef pair<string, string> pss;
    
    const double PI = 3.14159265358979323846264338327;
    const double E = exp(1);
    const double eps = 1e-30;
    
    const int INF = 0x3f3f3f3f;
    const int maxn = 1e4 + 5;
    const int MOD = 1e9 + 7;
    
    bool comp(char x, char y)
    {
        return x > y;
    }
    
    int main()
    {
        int t;
        scanf("%d", &t);
        while (t--)
        {
            string s;
            cin >> s;
            sort(s.begin(), s.end(), comp);
            int len = s.size();
            int vis;
            for (int i = len - 1; i >= 0; i--)
            {
                if (s[i] != '0')
                {
                    vis = i;
                    break;
                }
            }
            if (vis == 0)
                printf("Uncertain
    ");
            else
            {
                int num = s[vis] - '0';
                s.erase(vis, 1);
                len = s.size();
                for (int i = len - 1; i >= 0; i--)
                {
                    int temp = s[i] - '0';
                    num += temp;
                    s[i] = num % 10 + '0';
                    num /= 10;
                    if (num == 0)
                        break;
                }
                if (num)
                    cout << num;
                cout << s << endl;
            }
        }
    }
    
    
    
    
    
    
    
  • 相关阅读:
    vue路由传参页面刷新参数丢失问题解决方案
    理解MVC,MVP 和 MVVM
    HTTPS用的是对称加密还是非对称加密?
    元素显示隐藏的9种思路
    CSS中层叠上下文
    DOM盒模型和位置 client offset scroll 和滚动的关系
    css重点知识和bug解决方法
    你可能不知道的CSS
    如何在 React 中优雅的写 CSS?
    html5不常用标签应用场景
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433159.html
Copyright © 2011-2022 走看看