小红书-RED密码-c++

2017-09-28  本文已影响0人  Jacinth



#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;
}
上一篇下一篇

猜你喜欢

热点阅读