m0_53872613 2021-06-15 14:04 采纳率: 0%
浏览 14

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;
}

  • 写回答

2条回答 默认 最新

  • 关注

    把#include <string>

    改为

    #include <string.h>

    试试。

    评论

报告相同问题?

悬赏问题

  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开