QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#817262#9079. Hamming DistanceSGColinAC ✓2ms3980kbC++201.8kb2024-12-16 21:10:232024-12-16 21:10:27

Judging History

This is the latest submission verdict.

  • [2024-12-16 21:10:27]
  • Judged
  • Verdict: AC
  • Time: 2ms
  • Memory: 3980kb
  • [2024-12-16 21:10:23]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

int cnt, ty[10007];

char a[10007], b[10007], res[10007], p[10007];

inline void work(){
    memset(ty, 0, sizeof(ty));
    memset(p, 0, sizeof(p));
    scanf("%s", a + 1);
    scanf("%s", b + 1);
    printf("Case %d: ", ++cnt);
    int n = strlen(a + 1);
    int misa = 0, misb = 0;
    for (int i = 1; i <= n; ++i) {
        misa += a[i] != 'a';
        misb += b[i] != 'a';
        res[i] = 'a';
    }
    if (misa == misb) {
        for (int i = 1; i <= n; ++i) putchar('a');
        puts(""); return;
    }
    if (misa > misb) {
        swap(a, b);
        swap(misa, misb);
    }
    
    int dlt = misb - misa;
    for (int i = n; i; --i) {
        p[i] = '\0';
        if (a[i] == b[i]) continue;
        res[i] = b[i];
        if (a[i] == 'a') {
            dlt -= 2; 
            if (b[i] == 'b') {
                ty[i] = 2;
                p[i] = 'c';
            } else {
                ty[i] = 1;
                p[i] = 'b';
            }
        } else {
            if (b[i] == 'a') {
                ty[i] = 2;
                p[i] = (a[i] == 'b' ? 'c' : 'b');
            } else {
                dlt -= 1;
                ty[i] = 1;
                p[i] = 'a';
            }
        }
        if(dlt <= 0) break;
    }
    
    if (dlt < 0) {
        bool fl = 0;
        for (int i = 1; i <= n; ++i) 
            if (ty[i] == 1) {
                res[i] = p[i]; fl = 1; break;
            }
        if (!fl) {
            for (int i = n; i; --i) 
                if (ty[i] == 2) {
                    res[i] = p[i]; break;
                }
        }
    }
    for (int i = 1; i <= n; ++i) putchar(res[i]);
    puts("");
}
int main() {
    int t;
    scanf("%d", &t);
    while(t--) work();
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3832kb

input:

2
abc
acd
abandon
newyork

output:

Case 1: aaa
Case 2: aaaaark

result:

ok 6 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 3980kb

input:

3
abcbacjasiodjadosasadasdada
abcbacjasiodjadosasadasdada
aba
abb
bbbbbbaaaaa
aaaaaabbbbb

output:

Case 1: aaaaaaaaaaaaaaaaaaaaaaaaaaa
Case 2: aac
Case 3: aaaaabaaaac

result:

ok 9 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

1
aab
bba

output:

Case 1: abc

result:

ok 3 tokens

Test #4:

score: 0
Accepted
time: 0ms
memory: 3952kb

input:

1
aaaea
ccbdc

output:

Case 1: aabac

result:

ok 3 tokens

Test #5:

score: 0
Accepted
time: 2ms
memory: 3980kb

input:

100
y
m
tbqyaxbi
pqdqdayk
vdgccwsfo
wjgrckffn
hhka
bwqz
zcleuatejof
txpvaqmidwg
wbbl
fcuj
rfgjo
wfluk
ivimfoedco
lstisjtzfv
bhllf
puyfh
swuyfbufmz
swuyfbufmz
wvocvzngafbvnkfkbrcut
ldoxqnikmdtodzzzzmchs
lsfjwmjhszqiqhmwcrsaftrzvebgwhydynoiotqhqkrqhgxxuf
crvapaebmmxljfiiuoiiomnxhwwxgpulltbdwflgxgpezgc...

output:

Case 1: a
Case 2: aaaaaaaa
Case 3: aaaaaaaaa
Case 4: aaab
Case 5: aaaaaaaaaaa
Case 6: aaaa
Case 7: aaaaa
Case 8: aaaaaaaaaa
Case 9: aaaaa
Case 10: aaaaaaaaaa
Case 11: aaaaaaaaaaaaaaaaaaaas
Case 12: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaua
Case 13: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaxj
...

result:

ok 300 tokens

Extra Test:

score: 0
Extra Test Passed