C++Harry呀 2024-02-02 19:49 采纳率: 61.5%
浏览 2
已结题

please help me with c++

img


please help me with c++
please help me with c++
please help me with c++
please help me with c++please help me with c++please help me with c++please help me with c++

  • 写回答

3条回答 默认 最新

  • 龙傲天☆ 2024-02-02 20:32
    关注
    
    #include <bits/stdc++.h>
    using namespace std;
    string ma;
    bool cmp(string x) {
        int px = x.find(".");
        int pm = ma.find(".");
        string ix, fx, im, fm;
        if (px == -1 && pm == -1) {
            if (x.size() > ma.size() || (x.size() == ma.size() && x > ma)) return true;
        } else if (px!=-1 && pm !=-1) {
            ix = x.substr(0, px);
            fx = x.substr(px + 1);
            im = ma.substr(0, pm);
            fm = ma.substr(pm + 1);
        } else if (px != -1) {
            ix = x.substr(0, px);
            fx = x.substr(px + 1);
            im = ma;
        } else {
            ix = x;
            im = ma.substr(0, pm);
            fm = ma.substr(pm + 1);
        }
        if (ix.size() > im.size() || (ix.size() > im.size() && ix > im)) return true;
        else if (ix == im && fx > fm) return true;
        return false;
    }
    int main() {
        string s, w;
        getline(cin, s);
        for (int i = 0; i < s.size(); i++) {
            if (isdigit(s[i]) || s[i] == '.') {
                w += s[i];
                if (i == s.size() - 1 || (!isdigit(s[i + 1]) && s[i + 1] != '.')) {
                    if (cmp(w)) ma = w;
                    w = "";
                }
            }
        }
        cout << ma;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 2月10日
  • 已采纳回答 2月2日
  • 创建了问题 2月2日