求助大佬,为什么本地过得了,但是提交上去全都Wa了?
查看原帖
求助大佬,为什么本地过得了,但是提交上去全都Wa了?
1024853
sana_37楼主2023/6/28 22:30
#include<iostream>
using namespace std;
typedef struct
{
    string str;
}Num;
int cmp(const void* a, const void* b)
{
    Num* num1 = (Num*)b;
    Num* num2 = (Num*)a;
    if(num1->str.length()==num2->str.length())
    return num1->str.compare(num2->str);
    int lenght = (num1->str.length() > num2->str.length()) ? num2->str.length() : num1->str.length();
    if (num1->str.compare(0, lenght, num2->str, 0, lenght) == 0)
    {
        int ans = num1->str.compare(0, lenght, num2->str, 0, lenght);
        int l = lenght;
        while (ans == 0)
        {
            if (lenght < num1->str.length())
            { 
                ans = num1->str.compare(l, lenght, num2->str, 0, lenght);
                l += lenght;
            }
            else
            {
                ans = num2->str.compare(l, lenght, num1->str, 0, lenght);
                l += lenght;
            }
           
        }
        return ans;
    }
    else
    {
        return num1->str.compare(num2->str);
    }

    
    
}
int main()
{
    int N;
    cin >> N;
    Num* number = new Num[N];
    for (int i = 0; i < N; i++)
    {
        cin>>number[i].str;
    }
    qsort(number, N, sizeof(Num), cmp);
    for (int i = 0; i < N; i++)
    {
        cout << number[i].str;
    }








    return 0;
}

2023/6/28 22:30
加载中...