第一个题解过不了Udebug过了本题
查看原帖
第一个题解过不了Udebug过了本题
833124
BIOS楼主2023/11/30 22:31

第一个问题是第一个题解过不了Udebug,正如评论区所说的那样,存在hack样例可以卡掉“只考虑对立面匹配”的代码。

第二问题是,谁能帮我看看为什么两份代码输出不一样,我觉得我用map记录对立面也是一回事吧?

//map记录对立面
#include <iostream>
#include <string>
#include <cstring>
#include <map>
using namespace std;
string s;
map<pair<char, char>, int> ac;
char now[6], res[6], backup[6];
bool check(char c[])
{
    for (int i = 0; i < 6; i++)
        if (c[i] != res[i])
            return false;
    return true;
}
int main()
{
    while (cin >> s)
    {
        for (int i = 0; i < 6; i++)
            now[i] = s[i], res[i] = s[i + 6];
        ac.clear();
        ac[{now[0], now[5]}] = ac[{now[5], now[0]}] = 1;
        ac[{now[1], now[4]}] = ac[{now[4], now[1]}] = 1;
        ac[{now[2], now[3]}] = ac[{now[3], now[2]}] = 1;
        if (ac[{res[0], res[5]}] && ac[{res[1], res[4]}] && ac[{res[2], res[3]}])
            cout << "TRUE\n";
        else
            cout << "FALSE\n";
    }
}
//题解
#include <bits/stdc++.h>
using namespace std;
bool ans = false;
string a;
int b[130][130];
bool check()
{
    for (int i = 0; i <= 128; i++)
        for (int j = 0; j <= 128; j++)
            if (b[i][j])
                return false;
    return true;
}
int main()
{
    while (cin >> a)
    {
        ans = false;
        memset(b, 0, sizeof b);
        b[a[0]][a[5]]++, b[a[1]][a[4]]++, b[a[2]][a[3]]++;
        b[a[5]][a[0]]++, b[a[4]][a[1]]++, b[a[3]][a[2]]++;
        b[a[6]][a[11]]--, b[a[7]][a[10]]--, b[a[8]][a[9]]--;
        b[a[11]][a[6]]--, b[a[10]][a[7]]--, b[a[9]][a[8]]--;
        if (check())
            cout << "TRUE" << endl;
        else
            cout << "FALSE" << endl;
        memset(b, 0, sizeof(b));
    }
}
2023/11/30 22:31
加载中...