薇芊溢蕊渝薇吧 关注:32贴子:6,803
  • 2回复贴,共1

【暂时保存】JAVA程序

只看楼主收藏回复

import java.io.BufferedInputStream;
import java.util.Scanner;
public class TEST {
static Scanner sc = new Scanner(new BufferedInputStream(System.in));
public static void main(String[] args) {
int n = sc.nextInt();
String[] mn = new String[9];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 9; j++) {
mn[j % 3 * 3 + j / 3] = sc.next();
}
for (int j = 0; j < 9; j++) {
if (j % 3 == 2) {
System.out.println(mn[j]);
} else {
System.out.print(mn[j] + " ");
}
}
}
}
}


IP属地:安徽1楼2016-04-17 20:19回复
    import java.util.Scanner;
    public class Main {
    public static void main(String[] args) {
    int arr[] = new int[3];
    int temp;
    Scanner scan = new Scanner(System.in);
    for (int i = 0; i < arr.length; i++) {
    arr[i] = scan.nextInt();
    }
    for (int i = 0; i < arr.length; i++) {
    for (int j = 0; j < i; j++) {
    if (arr[i] < arr[j]) {
    temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
    }
    }
    }
    for (int k = 0; k < arr.length; k++) {
    System.out.println(arr[k]);
    }
    }
    }


    IP属地:安徽2楼2016-04-18 20:39
    回复
      /*
      * 描述
      有n盏灯,编号为1~n,第1个人把所有灯打开,第2个人按下所有编号为2 的倍数的开关(这些灯将被关掉),
      第3 个人按下所有编号为3的倍数的开关(其中关掉的灯将被打开,开着的灯将被关闭),
      依此类推。一共有k个人,问最后有哪些灯开着?输入:n和k,输出开着的灯编号。k≤n≤1000
      输入
      输入一组数据:n和k
      输出
      输出开着的灯编号
      样例输入
      7 3
      样例输出
      1 5 6 7
      */
      import java.util.Scanner;
      public class Main {
      public static void main(String[] args) {
      Scanner cs = new Scanner(System.in);
      int n, k;
      n = cs.nextInt();//灯数
      k = cs.nextInt();//人数
      boolean[] a = new boolean[n + 1];
      for (int i = 0; i < a.length; i++)
      a[i] = true;
      for (int i = 2; i <= k; i++) {//第一个循环控制第i个人去按开关
      for (int j = i; j <= n; j += i) {//第二个循环控制每个人所按开关的编号
      if (a[j])
      a[j] = false;
      else
      a[j] = true;
      }
      }
      for (int i = 1; i <= n; i++)
      if (a[i])
      System.out.print(i + " ");
      System.out.println();
      }
      }


      IP属地:安徽4楼2016-05-04 11:04
      回复