#29240: 範例中得到的輸出結果是對的,但是為什麼它一直寫我的輸出少了一行?


jayduck722@gmail.com (魔手環)

學校 : 不指定學校
編號 : 157751
來源 : [1.160.39.142]
最後登入時間 :
2022-06-11 22:28:29
b965. 2. 矩陣轉換 -- 2016年3月apcs | From: [1.160.27.81] | 發表日期 : 2022-02-08 14:01

#include <iostream>

using namespace std;

int main()
{
    int r,c,m;
    cin>>r>>c>>m;
    int ro[11][11],mo[11];
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
        cin>>ro[i][j];
        }
    }
    for(int i=0;i<m;i++)
    {
        cin>>mo[i];
    }
    
    for(int i=m-1;i>-1;i--)
    {
        if(mo[i]==1)
        {
            if(r%2==0)
            {
                for(int i=0;i<r/2;i++)
                {
                    for(int j=0;j<c;j++)
                    {
                        //cout<<ro[i][j]<<" "<<ro[r-1-j][j]<<endl;
                        int x=ro[i][j];
                        ro[i][j]=ro[r-1-i][j];
                        ro[r-1-i][j]=x;
                        
                    }
                }
            }
            else
            {
                for(int i=0;i<(r-1)/2;i++)
                {
                    for(int j=0;j<c;j++)
                    {
                        int x=ro[i][j];
                        ro[i][j]=ro[r-1-i][j];
                        ro[r-1-i][j]=x;
                    }
                }
            }
        }
        else
        {
            int a;
            a=r;
            r=c;
            c=a;
            int xo[10][10];
            for(int i=0;i<10;i++)
            {
                for(int j=0;j<10;j++)
                {
                    xo[i][j]=0;
                }
            }
            for(int i=0;i<r;i++)
            {
                for(int j=0;j<c;j++)
                {
                    xo[i][j]=ro[j][r-1-i];
                     
                }
            }
            for(int i=0;i<10;i++)
            {
                for(int j=0;j<10;j++)
                {
                    ro[i][j]=xo[i][j];
                }
            }       
        }
    }
    cout <<r<<" "<<c<<endl;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if(j==c-1)
            {
                cout<<ro[i][j];
            }
            else
            {
                cout<<ro[i][j]<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}

 
#29242: Re:範例中得到的輸出結果是對的,但是為什麼它一直寫我的輸出少了一行?


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.9.74.255]
最後登入時間 :
2024-10-14 22:20:08
b965. 2. 矩陣轉換 -- 2016年3月apcs | From: [27.247.197.101] | 發表日期 : 2022-02-08 17:49

#include <iostream>

using namespace std;

int main()
{
    int r,c,m;
    cin>>r>>c>>m;
    int ro[11][11],mo[11];
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
        cin>>ro[i][j];
        }
    }
    for(int i=0;i<m;i++)
    {
        cin>>mo[i];
    }
    
    for(int i=m-1;i>-1;i--)
    {
        if(mo[i]==1)
        {
            if(r%2==0)
            {
                for(int i=0;i<r/2;i++)
                {
                    for(int j=0;j<c;j++)
                    {
                        //cout<<ro[i][j]<<" "<<ro[r-1-j][j]<<endl;
                        int x=ro[i][j];
                        ro[i][j]=ro[r-1-i][j];
                        ro[r-1-i][j]=x;
                        
                    }
                }
            }
            else
            {
                for(int i=0;i<(r-1)/2;i++)
                {
                    for(int j=0;j<c;j++)
                    {
                        int x=ro[i][j];
                        ro[i][j]=ro[r-1-i][j];
                        ro[r-1-i][j]=x;
                    }
                }
            }
        }
        else
        {
            int a;
            a=r;
            r=c;
            c=a;
            int xo[10][10];
            for(int i=0;i<10;i++)
            {
                for(int j=0;j<10;j++)
                {
                    xo[i][j]=0;
                }
            }
            for(int i=0;i<r;i++)
            {
                for(int j=0;j<c;j++)
                {
                    xo[i][j]=ro[j][r-1-i];
                     
                }
            }
            for(int i=0;i<10;i++)
            {
                for(int j=0;j<10;j++)
                {
                    ro[i][j]=xo[i][j];
                }
            }       
        }
    }
    cout <<r<<" "<<c<<endl;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if(j==c-1)
            {
                cout<<ro[i][j];
            }
            else
            {
                cout<<ro[i][j]<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}


輸入多筆測資,所以要用while(cin>>r>>c>>m)

 
ZeroJudge Forum