topic
Title link
Problem-solving ideas
First reverse the first dimension, then reverse the second dimension.
Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(void)
{
ios::sync_with_stdio(false);
(0);
int n,m;
cin>>n>>m;
vector<string> a(n);
for(auto &e:a)
cin>>e;
reverse((),());
for(auto &s:a)
reverse((),());
for(auto &s:a)
cout<<s<<'\n';
return 0;
}
import ;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner();
int n,m,i,j;
n=();
m=();
String[] a=new String[n+5];
for(i=0;i<n;++i)
a[i]=();
for(i=0;i<n/2;++i)
{
String tmp=a[i];
a[i]=a[n-i-1];
a[n-i-1]=tmp;
}
for(i=0;i<n;++i)
a[i]=new StringBuilder(a[i]).reverse().toString();
for(i=0;i<n;++i)
(a[i]);
}
}
n,m=map(int,input().split())
a=[input() for i in range(0,n)]
()
for i in range(0,n):
a[i]=a[i][::-1]
for i in a:
print(i)
Algorithm and complexity
- Algorithm: Enumeration.
- Time complexity:\(\mathcal{O}(n \cdot m)\) 。
- Space complexity:\(\mathcal{O}(n \cdot m)\) 。
This is the solution to the Niuke input and output questions. Everyone is welcome to read the Niuke question bank. This is the solution to the Niuke input and output questions. Everyone is welcome to read the Niuke question bank. This is the solution to the Niuke input and output questions. Everyone is welcome to read the Niuke question bank. This is the solution to the Niuke input and output questions. Everyone is welcome to read the Niuke question bank. This is the solution to the Niuke input and output questions. Everyone is welcome to read the Niuke question bank.