头像

zmzmc




离线:2天前


最近来访(34)
用户头像
今天也是刷题的一天
用户头像
AC不了怎么办
用户头像
梦_511
用户头像
Laurus_1
用户头像
Zoltan
用户头像
梦醒夜续
用户头像
什么东西馋了过来
用户头像
Tiwwp
用户头像
weiwei3466
用户头像
Azusamitsusa
用户头像
lzq想要努力变胖
用户头像
check_check

活动打卡代码 AcWing 3482. 大数运算

zmzmc
25天前
import java.util.*;
import java.math.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        BigDecimal a = sc.nextBigDecimal();
        BigDecimal b = sc.nextBigDecimal();
        System.out.println(a.add(b));
        System.out.println(a.subtract(b));
        System.out.println(a.multiply(b));
    }
}


活动打卡代码 AcWing 3498. 日期差值

zmzmc
26天前
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
class Main{
    public static void main(String[] args) throws IOException, ParseException {
       Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            String s1 = sc.next();
            String s2 = sc.next();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            Date d1 = dateFormat.parse(s1);
            Date d2 = dateFormat.parse(s2);
            long t1 = d1.getTime();
            long t2 = d2.getTime();
            System.out.println(Math.abs(t1 - t2) / 1000 / 60 / 60 / 24 + 1);
        }
    }
}


活动打卡代码 AcWing 3497. 质数

zmzmc
26天前
import java.util.*;
class Main{
    static int[] primes = new int[200011];
    static boolean[] st = new boolean[200011];
    static int idx = 0;
    public static void get()
    {
        for(int i = 2;i <= 200010;i++){
            if(!st[i])primes[idx++] = i;
            for(int j = 0;primes[j] * i <= 200010;j++){
                st[primes[j] * i] = true;
                if(i % primes[j] == 0)break;
            }
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        get();
        while(sc.hasNext()){
            System.out.println(primes[sc.nextInt() - 1]);
        }
    }
}


活动打卡代码 AcWing 3480. 棋盘游戏

zmzmc
27天前
import javax.swing.plaf.IconUIResource;
import java.util.*;
class Main{
    static int[][] g = new int[6][6];
    static int[][][] d = new int[6][6][6];
    static int x1,y1,x2,y2;
    static class Node{
        int x,y,st,dis;
        Node(int a,int b,int c,int D){
            x = a;y = b;st = c;dis = D;
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i = 0;i < 6;i++){
            for(int j = 0;j < 6;j++){
                g[i][j] = sc.nextInt();

            }
        }
        for(int i = 0;i < 6;i++){
            for(int j = 0;j < 6;j++){
                for(int k = 0;k < 6;k++){
                    d[i][j][k] = 100000;
                }
            }
        }
        x1 = sc.nextInt();
        y1 = sc.nextInt();
        x2 = sc.nextInt();
        y2 = sc.nextInt();
        PriorityQueue<Node> Q = new PriorityQueue<>(new Comparator<Node>() {
            @Override
            public int compare(Node o1, Node o2) {
                if(o1.dis != o2.dis)return o1.dis - o2.dis;
                return o1.st - o2.st;
            }
        });
        for(int i = 0;i < 6;i++){
            d[x1][y1][i] = 0;
        }
        int[] dx = new int[]{1,0,-1,0};
        int[] dy = new int[]{0,1,0,-1};
        Q.add(new Node(x1,y1,1,0));
        while(Q.size() >= 1){
            Node t = Q.poll();
            for(int i = 0;i < 4;i++){
                int x = t.x + dx[i];
                int y = t.y + dy[i];
                if(x >= 0 && x < 6 && y >= 0 && y < 6){
                    int cost = t.st * g[x][y];
                    if(d[x][y][cost % 4] > t.dis + cost){
                        d[x][y][cost % 4] = t.dis + cost;
                        Q.add(new Node(x,y,cost % 4 + 1,d[x][y][cost % 4]));
                    }
                }
            }
        }
        int res = 1000000;
        for(int i = 0;i < 4;i++)res  = Math.min(res,d[x2][y2][i]);
        System.out.println(res);
    }
}


活动打卡代码 AcWing 3512. 最短距离总和

zmzmc
28天前
#include<bits/stdc++.h>
using namespace std;
const int N = 510;
int g[N][N];
int n;
int main()
{
    cin >> n;
    memset(g,10000000,sizeof g);
    for(int i = 1;i <= n;i++)
       for(int j = 1;j <= n;j++)
          cin >> g[i][j];
    long long res = 0;  
    for(int k = n;k >= 2;k--){
        for(int i = 1;i <= n;i++){
           for(int j = 1;j <= n;j++){
              g[i][j] = min(g[i][j],g[i][k] + g[k][j]);
             if(i >= k && j >= k){
                 res += g[i][j];
             }
           }
        }
    }
    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 3475. 简单密码

zmzmc
1个月前
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
             String st = sc.nextLine();
             if(st.equals("ENDOFINPUT"))
             break;
             String s = sc.nextLine();
             char[] c = s.toCharArray();
             int n = c.length;
             for(int i = 0;i < n;i++){
                 if(c[i] >= 'A' && c[i] <= 'Z'){
                     int diff = (c[i] - 'Z' - 5) % 26;
                     c[i] = (char)('Z' + diff);
                 }
             }
             System.out.println(new String(c));
             String ed = sc.nextLine();
        }
    }
}


活动打卡代码 AcWing 3473. 鸡兔同笼

zmzmc
1个月前
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
         while(t-- > 0){
             int n = sc.nextInt();
             int i = 0;
             //鸡少
             for(i = 0;i <= n / 2;i++){
                 if((n - i * 2) % 4  == 0){
                     System.out.print((n - i * 2) / 4 + i + " ");
                     break;
                 }
             }
             if(i == n / 2 + 1){
                 System.out.println("0 0");
             }
             else {
                 //兔少
                 for(i = 0;i <= n / 4;i++){
                 if((n - i * 4) % 2  == 0){
                     System.out.println((n - i * 4) / 2 + i);
                     break;
                 }
             }
             }
         }
    }
}


活动打卡代码 AcWing 3451. 字符串排序II

zmzmc
1个月前
import java.util.*;
class Main{
    static class Node{
        char c;
        int i;
        Node(char a,int b) {
            c = a;
            i = b;
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()){
            String s = sc.nextLine();
            char[] c = s.toCharArray();
            int n = c.length;
            int idx = 0;
            Node[] a = new Node[n];
            for(int i = 0;i < n;i++){
                if(c[i] >= 'A' && c[i] <= 'Z'){
                    a[idx++] = new Node(c[i],i);
                    c[i] = (char)100000;
                }else if(c[i] >= 'a' && c[i] <= 'z'){
                    a[idx++] = new Node(c[i],i);
                    c[i] = (char)100000;
                }
            }
            Arrays.sort(a, 0, idx, new Comparator<Node>() {
                @Override
                public int compare(Node o1, Node o2) {
                    if(Character.toLowerCase(o1.c) != Character.toLowerCase(o2.c))return Character.toLowerCase(o1.c) - Character.toLowerCase(o2.c);
                    return o1.i - o2.i;
                }
            });
            idx = 0;
            for(int i = 0;i < n;i++){
                if(c[i] == (char)100000)c[i] = a[idx++].c;
            }
            System.out.println(new String(c));
        }
    }
}


活动打卡代码 AcWing 3508. 最长公共子串

zmzmc
1个月前
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        int n = s1.length(),m = s2.length();
        int res = 0;
        int[][] f = new int[n + 1][m + 1];
        for(int i = 0;i < n;i++){
            for(int  j = 0;j < m;j++){
                if(s1.charAt(i) == s2.charAt(j) && s1.charAt(i) > '9' && s2.charAt(j) > '9'){
                    f[i + 1][j + 1] = f[i][j] + 1;
                    res = Math.max(res,f[i + 1][j + 1]);
                }
                else f[i + 1][j + 1] = 0;
            }
        }
        System.out.println(res);
    }
}


活动打卡代码 AcWing 3425. 小白鼠排队

zmzmc
1个月前
import java.util.*;
class Main{
    static class Node{
        int w;
        String s;
        Node(int a,String b){
            w = a;
            s = b;
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Node[] a = new Node[n];
        for(int i = 0;i < n;i++){
            a[i] = new Node(sc.nextInt(),sc.next());
        }
        Arrays.sort(a,(o1,o2) -> (o2.w - o1.w));
        for(int i = 0;i < n;i++){
            System.out.println(a[i].s);
        }
    }
}