文章

2

粉丝

65

获赞

2

访问

811

头像
旋转方阵 题解:Java语言版
P1216 福州大学2018年机试题
发布于2024年1月27日 23:52
阅读数 401

/**
 * 旋转方程
 *
 * @author Beyong
 * @date 2024/01/27 22:25
 **/
import java.util.*;
public class Poj1216 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] arr = new int[20][20];
        int total_number = n * n;
        int step = 1;
        int xPos = 0;
        int yPos = 0;
        int flag = 0;
        int loop_count = 1;
        while (total_number != 0) {
            arr[xPos][yPos] = step;
            step++;
            if(flag == 0) {
                if(xPos == n - loop_count) {
                    flag = 1;
                    yPos++;
                } else {
                    xPos++;
                }
            } else if(flag == 1) {
                if(yPos == n - loop_count) {
                    flag = 2;
                    xPos--;
                } else {
                    yPos++;
                }
            } else if (flag == 2) {
    ...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发