?
查看原帖
?
804115
yzm0325楼主2023/10/8 22:45

WA 80 pts,下了测试数据测了明明一模一样,是不是换行符之类的细节出了问题?求大佬解答

#include <bits/stdc++.h>
using namespace std;
string st;
int s, t, w, len;
void dfs(int ind) {
//    cout << ind << '\n';
    if(ind == w + 1) return; 
    else {
//        if(ind == w) cout << 1 << ' ';
//        else cout << 0 << ' ';
//        if(st[ind] != t + 'a' - 1) cout << 1 << ' ';
//        else cout << 0 << ' ';
//        if(ind == w && st[ind] != t + 'a' - 1) cout << 1 << ' ';
//        else cout << 0 << ' ';
//        if(st[ind + 1] != char(t + 'a' - len + ind)) cout << 1 << ' ';
//        else cout << 0 << ' ';
//        cout << '\n';
        if(ind != w &&/* st[ind] != t + 'a' - 1 ||*/ st[ind + 1] != char(t + 'a' - len + ind)) dfs(ind + 1);
        else {
//            cout << "hh";
            st[ind] = char(int(st[ind]) + 1);
            for(int i = ind + 1; i <= t; i++) st[i] = char(int(st[i - 1]) + 1);
        }
    }
}
bool check(string a) {
    for(int i = 1; i <= w; i++)
        if(a[i] != char(t + 'a' - 1 - len + i)) return 0;
    return 1;
}
int main() {
    cin >> s >> t >> w >> st;
    len = st.length();
    st = ' ' + st + char(t + 'a');
    if(check(st)) return 0;
    for(int i = 1; i <= 5; i++) {
        dfs(1);
        cout << st.substr(1, len) << '\n';
        if(check(st)) return 0;
    }
    return 0;
}
/*
WA 的数据:
5 20 8
fhijmpqt

*/
2023/10/8 22:45
加载中...