描述: java
把分数按下面的办法排成一个数表。编程
1/1 1/2 1/3 1/4.....测试
2/1 2/2 2/3....spa
3/1 3/2 ....code
4/1.....
.........orm
咱们以z字型方法给上表的每项编号。特定方法:第一项是1/1,而后是1/二、2/一、3/一、2/二、1/三、1/四、2/3……。编程输入项号N(1<=N<=100000),输出表中第N项。ci
输入:第一行有一个整数m(0<m<=10),表示有m组测试数据;随后有m行,每行有一个整数N;it
输出:输出表中第N项class
输入数据:
import
4 3 14 7 12345
输出数据:
2/1 2/4 1/4 59/99
/***************************************************************************/
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); for (int j = 0; j < a; j++) { int m = sc.nextInt(); int i; for (i = 1; m - i > 0; i++) { m = m - i; } if (i % 2 == 1) { System.out.println(i + 1 - m + "/" + m); } else { System.out.println(m + "/" + (i + 1 - m)); } } } }
.....谁来给我讲一下...14为何是2/4..
这是我原代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); for (int j = 0; j < a; j++) { int m = sc.nextInt(); int x = 1; int y = 1; for (int i = 1; i < m; i++) { if (y == 1) { y = x + 1; x = 1; } else { y--; x++; } } System.out.println(x + "/" + y); } } }
我本身手工找也是4/2 ... 为啥测试上就说2/4