搞了半天结果第一个点WA了,求大佬弄个hack代码的数据,谢谢!
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
string a;
int n, longest, maxn, pl;
int main() {
cin >> a;
string s[17] = {"0"};
for(int i = 0; i <= 38; i += 5) {
// printf("%d\n", i);
s[i / 5 + 1] += a[i];
// cout << s[i / 5 + 1] << endl;
s[i / 5 + 1] += a[i + 1];
// cout << s[i / 5 + 1] << endl;
s[i / 5 + 1] += a[i + 2];
// cout << s[i / 5 + 1] << endl;
s[i / 5 + 1] += a[i + 3];
// cout << s[i / 5 + 1] << endl;
if(i != 35) s[i / 5 + 1] += a[i + 4];
// cout << s[i / 5 + 1] << endl;
}
for(int i = 1; i <= 8; ++i) {
// cout << s[i] << endl;
// printf("%d\n", (i != 8 && s[i] == "0000:") || (i == 8 && s[i] == "0000"));
if(i != 8 && s[i] == "0000:")
longest++;
else if(i == 8 && s[i] == "0000") {
longest++;
if(maxn < longest) {
maxn = longest;
pl = i - longest + 1;
s[pl] = (pl == 1 ? "::" : ":");
for(int j = pl + 1; j <= pl + longest - 1; ++j)
s[j] = "";
}
}
else {
if(maxn < longest) {
maxn = longest;
pl = i - longest;
s[pl] = (pl == 1 ? "::" : ":");
for(int j = pl + 1; j <= pl + longest - 1; ++j)
s[j] = "";
}
}
}
// for(int i = 1; i <= 8; ++i)
// cout << s[i] << endl;
for(int i = 1; i <= 8; ++i) {
if(s[i][0] == '0') {
int j;
for(j = 0; j <= 2; ++j)
if(s[i][j] != '0') break;
for(j; j <= (i == 8 ? 3 : 4); ++j)
printf("%c", s[i][j]);
} else
cout << s[i];
}
}