美文网首页
小红书-RED密码-c++

小红书-RED密码-c++

作者: Jacinth | 来源:发表于2017-09-28 23:18 被阅读0次



    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <map>
    #include <string>
    #include <vector>
    #include <set>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <algorithm>
    #include <unordered_map>
    using namespace std;
    /*解题思路:*/
    
    int main() {
        string abc;
        cin >> abc; //输入字符串abc
        string str(abc);
        string::iterator it; //迭代器it
        for (it = str.begin(); it != str.end(); ++it) {
            if ((*it == 'R') && (*(it + 1) == 'E') && (*(it + 2) == 'D')) {
                str.erase(it); //删除it处的一个字符(it是个string类型的迭代器)
                str.erase(it);
                str.erase(it);
            }
        }
        cout << str << endl;
        string tmp;
        string max = "0";
        for (it = str.begin(); it <= str.end(); ++it) {
            cout << tmp << endl;
            if (it == str.end()) {
                break;
            }
            if ((*it >= '0') && (*it <= '9')) {
                tmp = tmp + *it;
            } else {
                if (tmp.length() > max.length())
                    max = tmp;
                else if (tmp.length() == max.length()) {
                    if (tmp > max)
                        max = tmp;
                }
                tmp.clear();
            }
        }
        if (tmp.length() > max.length())
            max = tmp;
        else if (tmp.length() == max.length()) {
            if (tmp > max)
                max = tmp;
        }
        if (max == "0")
            max = -1;
        cout << max << endl;
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:小红书-RED密码-c++

          本文链接:https://www.haomeiwen.com/subject/iucbextx.html