public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); int[] res = support(n); System.out.println(res[0] + "/" + res[1]); } } public static int[] support(int n){ int[] res = new int[2]; int count = 1; int rowIndex = 1; int colIndex = 1; boolean flag = true; //标识,表示转方向 if(n == 1){ res[0] = rowIndex; res[1] = colIndex; return res; } while(count != n) { if (rowIndex == 1 && flag) { colIndex++; count++; flag = false; } while (colIndex != 1 && count != n) { colIndex--; rowIndex++; count++; } if (colIndex == 1 && !flag) { rowIndex++; count++; flag = true; } while (rowIndex != 1 && count != n) { rowIndex--; colIndex++; count++; } } res[0] = rowIndex; res[1] = colIndex; return res; } }
点赞 2

相关推荐

12-27 22:35
门头沟学院 Java
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务