L1-054 福到了
题目链接-L1-054 福到了
输入样例 1:
$ 9
@ @@@@@
@@@ @@@
@ @ @
@@@ @@@
@@@ @@@@@
@@@ @ @ @
@@@ @@@@@
@ @ @ @
@ @@@@@
输出样例 1:
$$$$$ $
$ $ $ $
$$$$$ $$$
$ $ $ $$$
$$$$$ $$$
$$$ $$$
$ $ $
$$$ $$$
$$$$$ $
输入样例 2:
& 3
@@@
@
@@@
输出样例 2:
bu yong dao le
&&&
&
&&&
解题思路
先判断这个字正过来倒过去是否是一样的,如果不一样,flag置为1,不用刻意用一个数组去存这个倒过来的字,只需在输出的时候逆序输出就行,输出是记得把所有的’@'换为输入的字符c
具体操作见代码
附上代码
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n;
char c;
cin>>c>>n;
cin.ignore();//吃掉换行符
vector<string> s(N);
for(int i=0;i<n;i++)
getline(cin,s[i]);
bool flag=0;
for(int i=0;i<n&&!flag;i++)
for(int j=0;j<n;j++)
if(s[i][j]!=s[n-i-1][n-1-j])
flag=1;//如果倒过来不一样则flag置为1
if(!flag)
cout<<"bu yong dao le"<<endl;
for(int i=n-1;i>=0;i--){
for(int j=n-1;j>=0;j--){
if(s[i][j]=='@')
cout<<c;
else
cout<<s[i][j];
}
cout<<endl;
}
return 0;
}