巨人网络题解
1 简单模拟下就行 把10变为2 最后数最长2的个数
string s;
cin >> s;
int len = s.length();
int count = 0;
for (int i = 0; i < len;) {
while (s[i] == '2' &&i<len) {
i++;
}
int ileft = i;
int iright = i + 1;
while (iright <len && s[iright] == '2')
iright++;
if (s[ileft] == '1' && s[iright] == '0') {
s[ileft] = '2';
s[iright] = '2';
i = 0;
continue;
}
i++;
}
int res = 0;
for (int i = 0; i<len;) {
if (s[i] == '2') {
int tmp = 0;
while (i<len &&s[i] == '2') {
tmp++;
i++;
}
res = max(res, tmp);
continue;
}
i++;
}
cout << res;
cin >> s;
int len = s.length();
int count = 0;
for (int i = 0; i < len;) {
while (s[i] == '2' &&i<len) {
i++;
}
int ileft = i;
int iright = i + 1;
while (iright <len && s[iright] == '2')
iright++;
if (s[ileft] == '1' && s[iright] == '0') {
s[ileft] = '2';
s[iright] = '2';
i = 0;
continue;
}
i++;
}
int res = 0;
for (int i = 0; i<len;) {
if (s[i] == '2') {
int tmp = 0;
while (i<len &&s[i] == '2') {
tmp++;
i++;
}
res = max(res, tmp);
continue;
}
i++;
}
cout << res;
2 简单dfs
3 简答题