// Online C++ compiler to run C++ program online
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#include<iomanip>
#include<string.h>
#include<exception>
#include<map>
#include<cmath>
#include<unordered_map>
#include<set>
#include<climits>
#include<ctype.h>
#include<queue>
#include<stack>
using namespace std;
struct Item
{
string str;
bool flag;
int len;
};
int main() {
string str;
cin >> str;
vector<Item> list;
string token = "";
int state = 0;
int validLen = 0;
bool flag = true;
for (int i = 0; i < str.size(); )
{
if (0 == state)
{
if (str[i] == '0')
{
validLen = 0;
if (token.size() < 1)
{
token += str[i];
}
i++;
continue;
}
++validLen;
token += str[i++];
state = 1;
}
else if (1 == state)
{
++validLen;
if (str[i] == '0')
{
state = 2;
}
else
{
flag = false;
}
token += str[i++];
}
else if (2 == state)
{
++validLen;
if (str[i] == '0')
{
list.push_back({ token, flag, validLen});
token = "";
state = 0;
flag = true;
continue;
}
state = 1;
}
}
int idx = -1;
int maxLen = 0;
for (int i = 0; i < list.size(); ++i) {
if (list[i].flag)
continue;
if (list[i].len > maxLen)
idx = i;
}
if (idx > 0)
cout << list[idx].str;
else
cout << -1;
return 0;
}
华为OD机试-最长连续方波信号
最新推荐文章于 2024-03-25 17:39:38 发布