1 条题解
-
0
C :
#include<stdio.h> int main() { int a,b,i,j,n; scanf("%d%d%d",&n,&a,&b); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(i==a) printf("(%d,%d)",i,j); } } printf("\n"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(j==b) printf("(%d,%d)",i,j); } } printf("\n"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(j-i==b-a) printf("(%d,%d)",i,j); } } printf("\n"); for(i=n;i>0;i--) { for(j=n;j>0;j--) { if(j+i==b+a) printf("(%d,%d)",i,j); } } printf("\n"); return 0; }
C++ :
#include<iostream> #include<cmath> using namespace std; int main() { int N,i,j; cin >> N >> i >> j; for(int k=1; k<=N; ++k) cout << "(" << i << "," << k << ")"; cout << endl; for(int k=1; k<=N; ++k) cout << "(" << k << "," << j << ")"; cout << endl; if(j-i>=0) { for(int k=1; k<=N-(int)fabs(j-i); ++k) cout << "(" << k << "," << (int)fabs(j-i)+k << ")"; } else { for(int k=1; k<=N-(int)fabs(j-i); ++k) cout << "(" << (int)fabs(j-i)+k << "," << k << ")"; } cout << endl; if((i+j)-(N+1)>=0) { for(int k=N-(int)fabs((i+j)-(N+1)); k>=1; --k) cout << "(" << k+(int)fabs((i+j)-(N+1)) << "," << N+1-k << ")"; } else { for(int k=N-(int)fabs((i+j)-(N+1)); k>=1; --k) cout << "(" << k << "," << N-(int)fabs((i+j)-(N+1))-k+1 << ")"; } cout << endl; return 0; }/* 0 1 2 3 -1 0 1 2 -2 -1 0 1 -3 -2 -1 0 */
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); // N*N格 int i = scanner.nextInt(); // 第i行,格子(i,j) int j = scanner.nextInt(); // 第j列,格子(i,j) // (i,j)同一行上格子的位置 for (int a = 1; a <= N; a++) { System.out.print("(" + i + "," + a + ")"); } System.out.println(); // (i,j)同一列上格子的位置 for (int a = 1; a <= N; a++) { System.out.print("(" + a + "," + j + ")"); } System.out.println(); // 左上到右下对角线上的格子的位置 // 从上往下,所以小到大,++ for (int a = 1; a <= N; a++) { for (int b = 1; b <= N; b++) { if ((a - b) == (i - j)) { System.out.print("(" + a + "," + b + ")"); } } } System.out.println(); // 左下到右上对角线上的格子的位置 // 从下往上,所以大到小,-- for (int a = N; a >= 1; a--) { for (int b = N; b >= 1; b--) { if ((a + b) == (i + j)) { System.out.print("(" + a + "," + b + ")"); } } } } }
信息
- ID
- 2812
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者