头像

夜久




离线:1天前


最近来访(28)
用户头像
或许本该如此.
用户头像
thinkpius
用户头像
yxc
用户头像
acwing_52274
用户头像
超级酷在线coding
用户头像
努力学习的小白
用户头像
RageAgainsttheMachine
用户头像
succyag
用户头像
bakkali
用户头像
阿豪zZ
用户头像
R虎虎生威R
用户头像
LeoRiver
用户头像
AAAL
用户头像
Administrator_
用户头像
小曲儿
用户头像
9104
用户头像
Yoursalt
用户头像
Sign
用户头像
SELFIE1
用户头像
绘事后素

活动打卡代码 AcWing 727. 菱形

夜久
3天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int cx = n / 2, cy = n / 2;
        for (int i = 0; i < n; i ++ ) {
            for (int j = 0; j < n; j ++ ) {
                int d = Math.abs(i - cx) + Math.abs(j - cy);
                if (d <= n / 2)
                    System.out.printf("*");
                else
                    System.out.printf(" ");
            }
            System.out.println();
        }
    }
}


活动打卡代码 AcWing 726. 质数

夜久
3天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        while (n -- > 0) {
            int x = sc.nextInt();
            boolean isPrime = true;
            for (int i = 2; i * i <= x; i ++ )
                if (x % i == 0) {
                    isPrime = false;
                    break;
                }
            if (isPrime)
                System.out.printf("%d is prime\n", x);
            else
                System.out.printf("%d is not prime\n", x);
        }
    }
}


活动打卡代码 AcWing 725. 完全数

夜久
3天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        while (n -- > 0) {
            int x = sc.nextInt();
            int sum = -x;
            for (int i = 1; i * i <= x; i ++ )
                if (x % i == 0) {
                    sum += i;
                    if (i != x / i) sum += x / i;
                }

            if (sum == x)
                System.out.printf("%d is perfect\n", x);
            else
                System.out.printf("%d is not perfect\n", x);
        }
    }
}



夜久
3天前
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(), m = sc.nextInt();
            if (n <= 0 || m <= 0) break;

            if (n > m) {
                int t = n;
                n = m;
                m = t;
            }

            int sum = 0;
            for (int i = n; i <= m; i ++ ) {
                System.out.printf("%d ", i);
                sum += i;
            }

            System.out.printf("Sum=%d\n", sum);
        }
    }
}


活动打卡代码 AcWing 717. 简单斐波那契

夜久
3天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int a = 0, b = 1;
        for (int i = 0; i < n; i ++ ) {
            System.out.printf("%d ", a);
            int c = a + b;
            a = b;
            b = c;
        }
    }
}



夜久
3天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        while (n -- > 0) {
            int x = sc.nextInt(), y = sc.nextInt();
            if (x > y) {
                int t = x;
                x = y;
                y = t;
            }

            int sum = 0;
            for (int i = x + 1; i < y; i ++ )
                if (i % 2 != 0)
                    sum += i;

            System.out.println(sum);
        }
    }
}


活动打卡代码 AcWing 713. 区间 2

夜久
3天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int in = 0, out = 0;
        while (n -- > 0) {
            int x = sc.nextInt();
            if (x >= 10 && x <= 20) in ++ ;
            else out ++ ;
        }

        System.out.printf("%d in\n", in);
        System.out.printf("%d out\n", out);
    }
}


活动打卡代码 AcWing 718. 实验

夜久
3天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int c = 0, r = 0, f = 0, tot = 0;
        while (n -- > 0) {
            int a = sc.nextInt();
            String t = sc.next();
            tot += a;
            if ("C".equals(t)) c += a;
            else if ("R".equals(t)) r += a;
            else f += a;
        }

        System.out.printf("Total: %d animals\n", tot);
        System.out.printf("Total coneys: %d\n", c);
        System.out.printf("Total rats: %d\n", r);
        System.out.printf("Total frogs: %d\n", f);
        System.out.printf("Percentage of coneys: %.2f %%\n", c * 100.0 / tot);
        System.out.printf("Percentage of rats: %.2f %%\n", r * 100.0 / tot);
        System.out.printf("Percentage of frogs: %.2f %%\n", f * 100.0 / tot);
    }
}


活动打卡代码 AcWing 711. 乘法表

夜久
3天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 1; i <= 10; i ++ )
            System.out.printf("%d x %d = %d\n", i, n, i * n);
    }
}


活动打卡代码 AcWing 710. 六个奇数

夜久
3天前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if (x % 2 == 0) x ++ ;

        for (int i = 0; i < 6; i ++ )
            System.out.println(x + i * 2);
    }
}