头像

Lapis

同济大学




离线:1天前


最近来访(2)
用户头像
Sofia
用户头像
我是fw

活动打卡代码 AcWing 753. 平方矩阵 I

Lapis
1天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0) break;
            int[][] x = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    int t = (n+1)/2;
                    int y;
                    if(n % 2 == 1)
                        y = t - Math.max(Math.abs(i - n / 2),Math.abs(j - n / 2));
                    else
                        y = t - Math.max((int)Math.abs(i - n / 2+0.5),(int)Math.abs(j - n / 2+0.5));
                    x[i][j] = y;
                    System.out.printf("%d ",x[i][j]);
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


活动打卡代码 AcWing 743. 数组中的行

Lapis
1天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double[][] x = new double[12][12];
        int l = sc.nextInt();
        double count = 0;
        String s = sc.next();
        char c = s.charAt(0);
        for (int i = 0; i < 12; i++) {
            for (int j = 0; j < 12; j++) {
                x[i][j] = sc.nextDouble();
                if(l == i)
                    count += x[i][j];
            }
        }
        if(c == 'S')
            System.out.printf("%.1f",count);
        else
            System.out.printf("%.1f",count/12);
    }
}


活动打卡代码 AcWing 737. 数组替换

Lapis
1天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int[] x = new int[10];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 10; i++) {
            x[i] = sc.nextInt();
        }
        for (int i = 0; i < 10; i++) {
            if(x[i] <= 0)
                x[i] = 1;
        }
        for (int i = 0; i < 10; i++) {
            System.out.println("X["+i+"] = "+x[i]);
        }
    }
}


活动打卡代码 AcWing 727. 菱形

Lapis
1天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x,y;
        x = sc.nextInt();
        y = (x+1)/2;
        for (int i = 1; i <= y; i++) {
            for (int j = 1; j <= y - i ; j++) {
                System.out.print(' ');
            }
            for (int j = 0; j < 2*i-1; j++) {
                System.out.print('*');
            }
            System.out.print('\n');
        }
        for (int i = y + 1; i <= x ; i++) {
            for (int j = 1; j <= i - y ; j++) {
                System.out.print(' ');
            }
            for (int j = 0; j < 2*(x - i) + 1; j++) {
                System.out.print('*');
            }
            System.out.print('\n');
        }
    }
}


活动打卡代码 AcWing 724. 约数

Lapis
1天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x;
        x = sc.nextInt();
        for (int i = 1; i <= x; i++) {
            if(x % i == 0)
                System.out.println(i);
        }
    }
}


活动打卡代码 AcWing 721. 递增序列

Lapis
1天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int y;
        do{
            y = sc.nextInt();
            for (int i = 1; i <= y; i++) {
                System.out.print(i+" ");
            }
            if(y != 0)
                System.out.print('\n');
        }while(y != 0);
    }
}


活动打卡代码 AcWing 712. 正数

Lapis
1天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Double[] x = new Double[6];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 6; i++) {
            x[i] = sc.nextDouble();
        }
        int count = 0;
        for (int i = 0; i < 6; i++) {
            if(x[i] > 0)
                count++;
        }
        System.out.println(count+" positive numbers");
    }
}


活动打卡代码 AcWing 708. 偶数

Lapis
1天前
public class Main {
    public static void main(String[] args) {
//        String a,b,c;
//        Scanner sc = new Scanner(System.in);
//        a = sc.next();
//        b = sc.next();
//        c = sc.next();
        for (int i = 2; i < 101; i+=2) {
            System.out.println(i);
        }
    }
}


活动打卡代码 AcWing 670. 动物

Lapis
3天前
import java.util.Objects;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String a,b,c;
        Scanner sc = new Scanner(System.in);
        a = sc.next();
        b = sc.next();
        c = sc.next();
        if(Objects.equals(a, "vertebrado")){
            if(Objects.equals(b, "ave")){
                if(Objects.equals(c, "carnivoro"))
                    System.out.println("aguia");
                else if(Objects.equals(c, "onivoro"))
                    System.out.println("pomba");
            }
            else if (Objects.equals(b, "mamifero")) {
                if(Objects.equals(c, "onivoro"))
                    System.out.println("homem");
                else if(Objects.equals(c, "herbivoro"))
                    System.out.println("vaca");
            }
        }
        else if (Objects.equals(a, "invertebrado")) {
            if(Objects.equals(b, "inseto")){
                if(Objects.equals(c, "hematofago"))
                    System.out.println("pulga");
                else if(Objects.equals(c, "herbivoro"))
                    System.out.println("lagarta");
            }
            else if (Objects.equals(b, "anelideo")) {
                if(Objects.equals(c, "hematofago"))
                    System.out.println("sanguessuga");
                else if(Objects.equals(c, "onivoro"))
                    System.out.println("minhoca");
            }
        }
    }
}


活动打卡代码 AcWing 667. 游戏时间

Lapis
3天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int a,b;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        if(a == b)
            System.out.println("O JOGO DUROU 24 HORA(S)");
        else if(a < b)
            System.out.printf("O JOGO DUROU %d HORA(S)",b-a);
        else
            System.out.printf("O JOGO DUROU %d HORA(S)",24-a+b);

    }
}