4 solutions
-
0
``
#include <iostream> #include <stdio.h> int main() { int a[6][6]={0}; int b[6]; int x,y; for (int i = 1; i < 6; i++) { for (int j = 1; j < 6; j++) { scanf("%d", &a[i][j]); } } scanf("%d",&x); scanf("%d",&y); printf("\n"); for(int i=1;i<6;i++){ b[i]=a[x][i]; } for (int j = 1; j <6 ; ++j) { a[x][j]=a[y][j]; } for (int j = 1; j <6 ; ++j) { a[y][j]=b[j]; } for (int i = 1; i < 6; i++) { for (int j = 1; j < 6; ++j) { printf("%d ", a[i][j]); } printf("\n"); } return 0; }
-
0
偷懒用 string ,并且只交换行下标
#include <bits/stdc++.h> using namespace std; #define DBG(x) cout << #x << "=" << x << endl const int N = 5; int idxs[] = {-1, 1, 2, 3, 4, 5}; string g[N + 1]; void solve() { int m, n; for (int i = 1; i <= N; i++) getline(cin, g[i]); cin >> m >> n; swap(idxs[m], idxs[n]); for (int i = 1; i <= N; i++) cout << g[idxs[i]] << endl; } int main() { solve(); return 0; }
-
0
#include <stdio.h> int main(){ int a[6][6]; int b[6][6];//临时用来交换变量的中间商 int m,n; for(int i=1;i<=5;i++){ for(int j=1;j<=5;j++){ scanf("%d",&a[i][j]); } } scanf("%d%d",&n,&m); for(int j=1;j<=5;j++){ b[n][j]=a[n][j]; a[n][j]=a[m][j]; a[m][j]=b[n][j]; } for(int i=1;i<=5;i++){ for(int j=1;j<=5;j++){ if(j!=5) printf("%d ",a[i][j]); else printf("%d",a[i][j]); } printf("\n"); } return 0; }
-
0
#include <stdio.h> #include <algorithm> #include <math.h> #include <vector> #include <iostream> #include <string.h> #include <queue> using namespace std; int n,k; int a[10][10]; int main() { for(int i=0; i<5; i++) { for(int j=0; j<5; j++) scanf("%d",&a[i][j]); } scanf("%d%d",&n,&k); for(int i=0; i<5; i++) { for(int j=0; j<5; j++) { if(i==n-1) { if(j==4) printf("%d\n",a[k-1][j]); else printf("%d ",a[k-1][j]); } else if(i==k-1) { if(j==4) printf("%d\n",a[n-1][j]); else printf("%d ",a[n-1][j]); } else { if(j==4) printf("%d\n",a[i][j]); else printf("%d ",a[i][j]); } } } return 0; }
- 1
Information
- ID
- 86
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 4
- Tags
- # Submissions
- 259
- Accepted
- 119
- Uploaded By