第四届传智杯初赛B组 java代码

1.组原成绩

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        System.out.println((int)(a*0.2+b*0.3+c*0.5));

    }
}

2.报告赋分

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int m[]=new int[a];
        for (int i = 0; i <a ; i++) {
            int b=sc.nextInt();
            int c=sc.nextInt();
            if(c<16){
                b=b-10;
            }
            if(c>20){
                b=b-(c-20);
            }
            if(b<0){
                b=0;
            }
            m[i]=b;
        }
        for (int i = 0; i < m.length; i++) {
            System.out.println(m[i]);
        }
    }
}

3.竞争得分

import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int max=Integer.MIN_VALUE;
        int min=Integer.MAX_VALUE;
        int m[]=new int[a];
        for (int i = 0; i < a; i++) {
            m[i]=sc.nextInt();
            if(m[i]>max){
                max=m[i];
            }
            if(m[i]<min){
                min=m[i];
            }
        }
        for (int i = 0; i < m.length; i++) {
            System.out.println(100*(m[i]-min)/(max-min));
        }

    }
}

4.小卡与质数2
 

import java.util.*;


public class   Main {
    public static boolean isPrimeNumber(int n){
        if (n < 2) return false;
        for (int i=2;i<=Math.sqrt(n);i++){
            if (n % i == 0) return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int m[]=new int[a];
        for (int i = 0; i < a; i++) {
            int c=0;
            int k=sc.nextInt();
            for (int j = 0; j <k ; j++) {
                if(isPrimeNumber(k^j)==true){
                    c++;
                }

            }
            m[i]=c;
        }
        for (int i = 0; i < m.length; i++) {
            System.out.println(m[i]);
        }

     }


}

5.萝卜数据库

import java.util.*;


public class   Main {



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int m[] = new int[n];
        int p = 0;
        String o[] = new String[k + 1];
        Arrays.fill(o, "");
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a == 1) {
                int l = sc.nextInt();
                for (int j = 0; j < l; j++) {
                    int x = sc.nextInt();
                    int y = sc.nextInt();
                    o[x] += y + " ";

                }
            }
            if (a == 2) {
                int c = sc.nextInt();
                int min = sc.nextInt();
                int max = sc.nextInt();
                int s = 0;
                if(o[c]!=""){
                String q[] = o[c].split(" ");
                for (int j = 0; j < q.length; j++) {
                    if (q[j] != null) {
                        Integer h = Integer.valueOf(q[j]);
                        if (h >= min && h <= max) {
                            s++;
                        }
                    }
                }
                m[p]=s;
                p++;
            }}
        }
        for (int i = 0; i <p ; i++) {
            System.out.println(m[i]);
        }
    }
}

上一篇:用Java语句判断俩个值的大小


下一篇:PTA-乙级1008 数组元素循环右移问题 (20 分)-JAVA