#25031: 請各位大神幫我看看為什麼TLE?(c++)


morris20031031@gmail.com (damn91)

學校 : 國立臺中第一高級中學
編號 : 147796
來源 : [36.238.212.164]
最後登入時間 :
2023-12-19 16:30:15
c381. 聖經密碼 -- 板橋高中教學題 | From: [42.76.174.51] | 發表日期 : 2021-04-15 09:49

#include<iostream>

#include<string>

using namespace std;

 

int main()

{

    int n,m;

    while(cin >> n >> m) {

        if(n==0 && m==0) {

            break;

        }

        else {

            string a,b;

            int c;

            for(int i=0;i<n;i++){

                cin >> a;

                b = b + a;

            }

            for(int i=0;i<m;i++){

                cin >> c;

                cout << b[c-1];

            }

        }

    }

    cout << endl;

    return 0;

}

 
#25126: Re:請各位大神幫我看看為什麼TLE?(c++)


abs71507@gmail.com (46 5)

學校 : 國立中興大學
編號 : 87742
來源 : [36.235.200.136]
最後登入時間 :
2023-05-24 14:06:42
c381. 聖經密碼 -- 板橋高中教學題 | From: [42.73.70.79] | 發表日期 : 2021-04-22 20:07

#include

#include

using namespace std;

 

int main()

{

    cin.tie(NULL);

    ios_base::sync_with_stdio(false);

    int n,m;

    while(cin >> n >> m) {

        if(n==0 && m==0) {

            break;

        }

        else {

            string a,b;

            cin.get();

            int c;

            for(int i=0;i<n;i++){

                getline(cin,a);

                b += a;

            }

            for(int i=0;i<m;i++){

                cin >> c;

                cout << b[c-1];

            }

        }

        cout << endl;

    }

    cout << endl;

    return 0;

}

 

 

AC (21ms, 22.3MB)

修改後就行了

 
ZeroJudge Forum