PAT basic level - Dan diamond like Four volumes to 2-7-5 (15 points)

"Fu" stick backwards, meaning "blessing to." Whether in the end count folk, this question and ask you to write a program, the various characters upside down output. Where each character to be processed is a N  × N grid consisting of grid elements or a character  @ or a space. The character upside down characters used by the designated referees.

Input formats:

In the first row given input inverted characters used in character, and the mesh size N (a positive integer not exceeding 100), separated by a space therebetween; then N rows, each row gives N characters, or to  @ or for the space.

Output formats:

Inverted output grid, as shown in the sample. However, if the word is coming this fall is the same as in the past, on the first output bu yong dao le, and then enter the character specified outputs.

Sample Input 1:

$ 9
 @  @@@@@
@@@  @@@ 
 @   @ @ 
@@@  @@@ 
@@@ @@@@@
@@@ @ @ @
@@@ @@@@@
 @  @ @ @
 @  @@@@@

Output Sample 1:

$$$$$  $ 
$ $ $  $ 
$$$$$ $$$
$ $ $ $$$
$$$$$ $$$
 $$$  $$$
 $ $   $ 
 $$$  $$$
$$$$$  $ 

Sample Input 2:

& 3
@@@
 @ 
@@@

Output Sample 2:

bu yong dao le
&&&
 & 
&&&


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    string s,tmp,tmp2;int N;
    cin>>s>>N;getline(cin,tmp);
    vector<string> v,v_ini;
    while(N--){
        getline(cin,tmp);
        tmp2=tmp;
        reverse(tmp.begin(),tmp.end());
        v.push_back(tmp);
        v_ini.push_back(tmp2);
    }
    reverse(v.begin(),v.end());
    bool reverse_=true;
    for(int i=0;i<v.size();i++)
        if(v[i]!=v_ini[i]) reverse_=false;
    if(reverse_){
        cout<<"bu yong dao le"<<endl;
        for(int i=0;i<v_ini.size();i++){
            for(int j=0;j<v_ini[i].size();j++)
                if(v_ini[i][j]=='@') cout<<s;
                else cout<<" ";
            cout<<endl;
        }
    }else{
        for(int i=0;i<v.size();i++){
            for(int j=0;j<v[i].size();j++)
                if(v[i][j]=='@') cout<<s;
                else cout<<" ";
            cout<<endl;
        }
    }
    system("pause");
    return 0;
}

 

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11966807.html