[PTA] blessing to 7 - 14

Title repeat

"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 by a grid consisting of N × N, the grid elements or @ 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 as @ or spaces.

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
&&&
 & 
&&&

answer

This question is not difficult, but need a place to note

  1. The idea is to find the relationship between the word and the word of the input-output relationship is that if the input is [i][j], the output position is[n-i-1][n-j-1]
  2. I used the input and getline cin, cin for input characters and n, should pay attention to once every problem, when cin receives a carriage return, it will receive input, but the carriage is still in the buffer, the buffer will then getline Enter eat in, resulting in incorrect output, so we can add between cin and getlien cin.ignore()ways to eliminate Enter.

100 ++ AND

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int store[105][105];
    int arr[105][105];
    char a,tmp;
    int n;
    cin>>a>>n;
    string str="";
    cin.ignore();
    for(int i=0; i<n; i++)
    {
        getline(cin,str);
        for(int j=0; j<n; j++)
        {

            if(str[j]=='@')
            {
                store[i][j]=1;
                arr[n-i-1][n-j-1]=1;
            }
            else
            {
                store[i][j]=0;
                arr[n-i-1][n-j-1]=0;
            }
        }
    }
    bool flag=true;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(store[i][j]!=arr[i][j])
            {
                flag=false;//如果有不一样的地方
            }
        }
    }
    if(flag)//如果没有不一样的地方,需额外输出
    {
        cout<<"bu yong dao le"<<endl;
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(arr[i][j]==1)
            {
                cout<<a;
            }
            else
            {
                cout<<' ';
            }
        }
        cout<<endl;
    }
    return 0;
}

Published 200 original articles · won praise 99 · views 40000 +

Guess you like

Origin blog.csdn.net/weixin_43889841/article/details/104014737