1 条题解

  • 0
    @ 2021-6-14 23:25:14

    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 */
    

    Pascal :

    var o,u,k,p,n,a,b,l,m,i:longint;
    begin
     readln(n,a,b);
     for i:=1 to n do write('(',a,',',i,')');
     writeln;
     for i:=1 to n do write('(',i,',',b,')');
     writeln;
     i:=0;
     if b>a then begin l:=b;m:=a;end
      else begin l:=a;m:=b;end;
     if a<b then begin
     for i:=1 to n-l+m do write('(',i,',',i+l-m,')');
      end
      else
      repeat
       i:=i+1;
       write('(',i+(l-m),',',i+(l-m)-(l-m),')') ;
      until i+(l-m)=n;
     writeln;
     if l+m-1>n then
      begin
      l:=n-l+1;
      m:=n-m+1;
      if l>m then
      begin
      o:=l;u:=m;
      end
      else
      begin u:=l;o:=m;
      end;
      k:=n-l-1-(o-u) div 2;
      p:=n-m-1-(u-o) div 2;
      end;
     for i:=1  to l+m-1  do write('(',l+m-i+k,',',i+p,')');
    end.
    

    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 + ")");
    				}
    			}
    		}
    	}
    }
    
    • 1

    信息

    ID
    178
    时间
    1000ms
    内存
    125MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者