程序版本一:
//noname
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Scanner;
public class noname
{
public static void main(String[] args)
{
try{
Scanner scanner = new Scanner(new File("noname.in"));
File file = new File("noname.out"); //存放数组数据的文件
FileWriter out = new FileWriter(file); //文件写入流
int S = scanner.nextInt();
int T = scanner.nextInt();
int N = scanner.nextInt();
int c = 0;
int[][] matrix = new int[N][N];
for(int i = 0;i < N;i++)
{
for(int j = 0;j < N-i;j++)
{
matrix[j][i] = S + c;
if( matrix[j][i] == T)
{
S = 1;
c = 0;
continue;
}
c++;
}
}
for(int i = 0;i < N;i++)
{
for(int j = 0;j < N-i;j++)
{
out.write(matrix[i][j] + " ");
}
out.write("\n");
}
//Writer.write(String.valueOf(matrix.trim()));
scanner.close();
out.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
};
程序版本二:
//noname
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Scanner;
public class noname {
public static void main(String[] args) {
try {
Scanner scanner = new Scanner(new File("noname.in"));
Writer writer = new FileWriter("noname.out");
int s = scanner.nextInt();
int t = scanner.nextInt();
int n = scanner.nextInt();
int d = s;
String str = "";
int[][] data = new int[n][n];
for (int i=0; i<n; i++){
for (int j=0; j<n-i; j++){
data[j][i] = d;
d++;
if (d > t){
d=1;
}
}
}
for (int i=0; i<n; i++){
for (int j=0; j<n-i; j++){
str = str + data[i][j] + " ";
}
str = str.substring(0, str.length() - 1);
str = str + "\n\r";
}
writer.write(String.valueOf(str.trim()));
scanner.close();
writer.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}