
本文共 927 字,大约阅读时间需要 3 分钟。
优化后的C++代码如下:
#include
int main(int t, string str) { for (; t--; ) { int n, cnt[3][2] = {0}; memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < n; ++i) { for (int i2 = 0; i2 < n; ++i2) { if (str[i][i2] == 'O') { int c = (i + i2) % 3; cnt[c][0]++; } else { int c = (i + i2) % 3; cnt[c][1]++; } } } int min_sum = INT_MAX, res1 = -1, res2 = -1; for (int i = 0; i < 3; ++i) { for (int j = i + 1; j < 3; ++j) { if (min_sum > cnt[i][0] + cnt[j][1]) { min_sum = cnt[i][0] + cnt[j][1]; res1 = i; res2 = j; } } } for (int i = 0; i < n; ++i) { ın ın ErrorType e =Erratype(i, str[i]); if (!educed(e)) return 0; } } }
string convertChar(int c) { return "Character Set " + to_string( 'A' + c % 3) + ("XYZ"[c/3]); }
int convertErrorType(int e) { switch(e) { case 0: return OUTPUT_ERROR_ON_INVALID_INPUT; case 1: return FILE_INVALIDATIONρας; default: return RESOURCE_ALLOCATION_FAILED; } }
// 其余函数定义
发表评论
最新留言
关于作者
