#29391: 為何是0分?(C++)


chungkuanhung@gmail.com (鍾冠泓)

學校 : 國立中興大學
編號 : 176731
來源 : [111.82.39.188]
最後登入時間 :
2025-05-20 14:44:16

#include <iostream>

using namespace std;

int main(){

    int r,c,m;

    while(cin>>r>>c>>m){

        int a[10][10],b[10][10],x[m];

        for(int i=0;i<r;i++)

            for(int j=0;j<c;j++)

                cin>>a[i][j];

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

                cin>>x[i];

        for(int i=m;i>=0;i--){

            if(x[i]==0){

                for(int j=c-1;j>=0;j--)

                    for(int k=0;k<r;k++)

                        b[c-1-j][k]=a[k][j];

                int tmp=r;

                r=c;

                c=tmp;

                for(int j=0;j<r;j++)

                    for(int k=0;k<c;k++)

                        a[j][k]=b[j][k];

            }

            else if(x[i]==1){

                for(int j=r-1;j>=0;j--)

                    for(int k=0;k<c;k++)

                        b[r-1-j][k]=a[j][k];

                for(int j=0;j<r;j++)

                    for(int k=0;k<c;k++)

                        a[j][k]=b[j][k];

            }

        }

        cout<<endl<<r<<" "<<c<<endl;

        for(int j=0;j<r;j++){

            for(int k=0;k<c;k++){

                if(k==0)

                    cout<<a[j][k];

                else

                    cout<<" "<<a[j][k];

            }

            cout<<endl;

        }

    }

    return 0;

}

#29396: Re:為何是0分?(C++)


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.12.66.21]
最後登入時間 :
2025-04-20 17:19:22


        cout<<endl<<r<<" "<<c<<endl;


你前面多輸出了一個換行

#34226: Re: 為何是0分?(C++)


kk20180820@gmail.com (Wayne Yang)

學校 : 國立鳳山高級中學
編號 : 172018
來源 : [49.159.255.92]
最後登入時間 :
2025-08-10 14:18:00

#include

using namespace std;

int main(){

    int r,c,m;

    while(cin>>r>>c>>m){

        int a[10][10],b[10][10],x[m];

        for(int i=0;i

            for(int j=0;j

                cin>>a[i][j];

        for(int i=0;i

                cin>>x[i];

        for(int i=m;i>=0;i--){

            if(x[i]==0){

                for(int j=c-1;j>=0;j--)

                    for(int k=0;k

                        b[c-1-j][k]=a[k][j];

                int tmp=r;

                r=c;

                c=tmp;

                for(int j=0;j

                    for(int k=0;k

                        a[j][k]=b[j][k];

            }

            else if(x[i]==1){

                for(int j=r-1;j>=0;j--)

                    for(int k=0;k

                        b[r-1-j][k]=a[j][k];

                for(int j=0;j

                    for(int k=0;k

                        a[j][k]=b[j][k];

            }

        }

        cout<

        for(int j=0;j

            for(int k=0;k

                if(k==0)

                    cout<

                else

                    cout<<" "<

            }

            cout<

        }

    }

    return 0;

而且題目有要求印出的陣列每行最後面不能有空白,大大的程式碼似乎會多出一個空白