WA, length not correct答案长度不一致
查看原帖
WA, length not correct答案长度不一致
312583
Nahida_JiaraDiana楼主2023/3/8 02:58

随手一写发现7 9 11 13 15 16监测点WA了,报答案长度不一致,呜呜,思路应该是没问题,就是写的复杂了。深夜写的可能没考虑优化(),有没有大佬帮忙看一下哪里会导致答案长度不一致的。

#include<iostream>
#include<cstring>
using namespace std;

// abcdefghijklmnopqrstuvwxyz

int main(){
    int n;
    char* s1 = new char();
    char* s2 = new char();
    while(cin >> n){
        int flag = 1;
        char ans[n];
        cin >> s1 >> s2;
        for (int i = 0; i < n; i++){
            if(s1[i]-'a' < s2[i]-'a'){
                flag = 0;
                break;
            }
            else{
                ans[i] = s2[i];
            }
        }
        if(flag != 0){
            cout << ans << endl;
        }else{
            cout << "-1" << endl;
        }
        memset(ans, 0, sizeof(ans));
    }
    return 0;
}
2023/3/8 02:58
加载中...