#29393: 不知道為何會OLE


s111010137@student.nqu.edu.tw (Khazix)

學校 : 國立金門大學
編號 : 177202
來源 : [1.172.139.67]
最後登入時間 :
2022-11-09 22:20:56
c010. 10107 - What is the Median? -- UVa10107 | From: [27.52.232.70] | 發表日期 : 2022-02-24 16:12

#include <iostream>

using namespace std;

void sort(int n[], int i);

void swap(int* a, int* b);

int main(void)

{

    cin.tie(0);

    std::ios::sync_with_stdio(false);

 

    int i, num;

    int n[10002] = { 0 };

    

    i = 1;

 

    while (i < 10000)

    {

        cin >> n[i];

 

        sort(n, i);

 

        if (i % 2 == 1)

        {

            cout << n[(i + 1) / 2] << '\n';

        }

 

        else

        {

            cout << (n[i / 2] + n[(i / 2) + 1]) / 2 << '\n';

        }

 

        i++;

    }

 

    return 0;

}

 

void sort(int n[], int i)

{

    int num;

 

    num = n[i];

 

    for (int j = i - 1; j >= 1; j--)

    {

        if (n[j] > num)

        {

            swap(n[j], n[j + 1]);

        }

 

        else

        {

            break;;

        }

    }

 

    return;

}

 

void swap(int* a, int* b)

{

    int temp;

 

    temp = *a;

    *a = *b;

    *b = temp;

 

    return;

}

 
#29394: Re:不知道為何會OLE


linlincaleb@gmail.com (臨末之頌)

學校 : 新北市立板橋高級中學
編號 : 132772
來源 : [111.248.111.135]
最後登入時間 :
2023-04-01 22:41:13
c010. 10107 - What is the Median? -- UVa10107 | From: [203.64.161.156] | 發表日期 : 2022-02-24 17:05

#include

using namespace std;

void sort(int n[], int i);

void swap(int* a, int* b);

int main(void)

{

    cin.tie(0);

    std::ios::sync_with_stdio(false);

 

    int i, num;

    int n[10002] = { 0 };

    

    i = 1;

 

    while (i < 10000)

    {

        cin >> n[i];

 

        sort(n, i);

 

        if (i % 2 == 1)

        {

            cout << n[(i + 1) / 2] << '\n';

        }

 

        else

        {

            cout << (n[i / 2] + n[(i / 2) + 1]) / 2 << '\n';

        }

 

        i++;

    }

 

    return 0;

}

 

void sort(int n[], int i)

{

    int num;

 

    num = n[i];

 

    for (int j = i - 1; j >= 1; j--)

    {

        if (n[j] > num)

        {

            swap(n[j], n[j + 1]);

        }

 

        else

        {

            break;;

        }

    }

 

    return;

}

 

void swap(int* a, int* b)

{

    int temp;

 

    temp = *a;

    *a = *b;

    *b = temp;

 

    return;

}

沒說N是多少



 
#29397: Re:不知道為何會OLE


s111010137@student.nqu.edu.tw (Khazix)

學校 : 國立金門大學
編號 : 177202
來源 : [1.172.139.67]
最後登入時間 :
2022-11-09 22:20:56
c010. 10107 - What is the Median? -- UVa10107 | From: [27.52.232.70] | 發表日期 : 2022-02-24 18:08

#include

using namespace std;

void sort(int n[], int i);

void swap(int* a, int* b);

int main(void)

{

    cin.tie(0);

    std::ios::sync_with_stdio(false);

 

    int i, num;

    int n[10002] = { 0 };

    

    i = 1;

 

    while (i < 10000)

    {

        cin >> n[i];

 

        sort(n, i);

 

        if (i % 2 == 1)

        {

            cout << n[(i + 1) / 2] << '\n';

        }

 

        else

        {

            cout << (n[i / 2] + n[(i / 2) + 1]) / 2 << '\n';

        }

 

        i++;

    }

 

    return 0;

}

 

void sort(int n[], int i)

{

    int num;

 

    num = n[i];

 

    for (int j = i - 1; j >= 1; j--)

    {

        if (n[j] > num)

        {

            swap(n[j], n[j + 1]);

        }

 

        else

        {

            break;;

        }

    }

 

    return;

}

 

void swap(int* a, int* b)

{

    int temp;

 

    temp = *a;

    *a = *b;

    *b = temp;

 

    return;

}

沒說N是多少




可是N不是小於10000個嗎?

 
#29398: Re:不知道為何會OLE


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
c010. 10107 - What is the Median? -- UVa10107 | From: [110.26.163.180] | 發表日期 : 2022-02-24 18:15

#include

using namespace std;

void sort(int n[], int i);

void swap(int* a, int* b);

int main(void)

{

    cin.tie(0);

    std::ios::sync_with_stdio(false);

 

    int i, num;

    int n[10002] = { 0 };

    

    i = 1;

 

    while (i < 10000)

    {

        cin >> n[i];

 

        sort(n, i);

 

        if (i % 2 == 1)

        {

            cout << n[(i + 1) / 2] << '\n';

        }

 

        else

        {

            cout << (n[i / 2] + n[(i / 2) + 1]) / 2 << '\n';

        }

 

        i++;

    }

 

    return 0;

}

 

void sort(int n[], int i)

{

    int num;

 

    num = n[i];

 

    for (int j = i - 1; j >= 1; j--)

    {

        if (n[j] > num)

        {

            swap(n[j], n[j + 1]);

        }

 

        else

        {

            break;;

        }

    }

 

    return;

}

 

void swap(int* a, int* b)

{

    int temp;

 

    temp = *a;

    *a = *b;

    *b = temp;

 

    return;

}

沒說N是多少




可是N不是小於10000個嗎?


你有自己測試過嗎?

你的程式沒有偵測EOF,所以就算N很小,你的程式還是會輸出10000行

 
#29399: Re:不知道為何會OLE


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
c010. 10107 - What is the Median? -- UVa10107 | From: [110.26.163.180] | 發表日期 : 2022-02-24 18:19


    while (i < 10000)

    {

        cin >> n[i];


所以這裡可以改成

while (cin >> n[i])

 
#29400: Re:不知道為何會OLE


s111010137@student.nqu.edu.tw (Khazix)

學校 : 國立金門大學
編號 : 177202
來源 : [1.172.139.67]
最後登入時間 :
2022-11-09 22:20:56
c010. 10107 - What is the Median? -- UVa10107 | From: [27.52.232.70] | 發表日期 : 2022-02-24 18:31


    while (i < 10000)

    {

        cin >> n[i];


所以這裡可以改成

while (cin >> n[i])

 


感謝大老!

成功AC了

原來是這個問題...

忽略了...

感激不盡!


 
ZeroJudge Forum