poj2503为什么我的代码wrong answer呢?

POJ2503的代码,在自己编译器上实验无数遍是正确的,为什么一提交就是WA呢?我有遗漏了什么吗?球球急回答

 

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
const int MAX = 100001;
struct dictionary
{
    char word1[11];
    char word2[11];
}dict[MAX];
int quickpass(dictionary dict[], int low, int high)
{
    int down = low, up = high;
    dictionary x = dict[down];
    while (down < up)
    {
        while (down < up && strcmp(dict[up].word2, x.word2) > 0)
            up--;
        if (down < up) dict[down++] = dict[up];
        while (down < up && strcmp(dict[down].word2, x.word2) < 0)
            down++;
        if (down < up) dict[up--] = dict[down];
    }
    dict[down] = x;
    return down;
}
void quicksort(dictionary dict[], int low, int high)
{
    int mid;
    if (low < high)
    {
        mid = quickpass(dict, low, high);
        quickpass(dict, low, mid - 1);
        quickpass(dict, mid + 1, high);
    }
}
int binarysearch(char str[], int num)
{
    int low = 0, high = num - 1;
    int mid, judge;
    while (low <= high)
    {
        mid = (low + high) / 2;
        judge = strcmp(str, dict[mid].word2);
        if (judge == 0) return mid;
        else if (judge == -1) high = mid - 1;
        else low = mid + 1;
    }
    return -1;
}
int main()
{
    char str[255], str1[25], str2[25];
    int pos1 = 0, pos2 = 0, num = 0;
    while (cin.getline(str, 255))
    {
        if (str[0] == '\0') break;
        pos1 = 0; pos2 = 0;
        while (str[pos1] != ' ')
            str1[pos1] = str[pos1++];
        str1[pos1] = '\0';
        pos1++;
        while (str[pos1] != '\0')
            str2[pos2++] = str[pos1++];
        str2[pos2] = '\0';
        strcpy_s(dict[num].word1, strlen(str1) + 1, str1);
        strcpy_s(dict[num].word2, strlen(str2) + 1, str2);
        num++;
    }
    quicksort(dict, 0, num - 1);
    while (gets_s(str))
    {
        pos1 = binarysearch(str, num);
        if (pos1 == -1) cout << "eh" << endl;
        else cout << dict[pos1].word1 << endl;
    }
    return 0;
}

把#include <string>

改为

#include <string.h>

试试。

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps: 问答会员年卡【8折】购 ,限时加赠IT实体书,即可 享受50次 有问必答服务,了解详情>>>https://t.csdnimg.cn/RW5m