欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > 杭电OJ刷题记录(四):回归水题

杭电OJ刷题记录(四):回归水题

2024/10/26 0:31:20 来源:https://blog.csdn.net/zoe2222226666/article/details/142653321  浏览:    关键词:杭电OJ刷题记录(四):回归水题

2012—2023

import java.util.Scanner;
import java.text.DecimalFormat;import java.util.ArrayList;
import java.util.Collections;
import java.util.List;public class Day4 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);// 2012.素数判定
//        while(sc.hasNext()){
//            int x = sc.nextInt(), y = sc.nextInt();
//            int res  =0;
//            if(x ==0 && y==0)break;排序,以防万一
//            int tmp;
//            if (x>y){
//                tmp = x;
//                x = y;
//                y =tmp;
//            }
//            boolean flag=true;
//            for( int i=x;i<=y;i++){
//                res = i*i+i+41;
//                if (res % 2 ==0 && res != 2){
//                    flag = false;
//                    break;
//                }质数判定:用小于等于平方根的数去除,考虑2、3、5、7,虽然不在本题的取值范围内
//                int sqrt = (int) Math.sqrt(res);
//                for(int j=2;j<=sqrt;j++){
//                    if (res % j == 0){
//                        flag = false;
//                        break;
//                    }
//                }
//            }
//            if (flag){
//                System.out.println("OK");
//            }
//            else{
//                System.out.println("Sorry");
//            }
//        }//  2013.蟠桃记
//        while(sc.hasNext()){
//            int n = sc.nextInt();
//            int total = 1;
//                for(int i = 1; i < n; i++){
//                    total = 2* total +2;
//                }
//                System.out.println(total);
//        }//  2014.青年歌手大奖赛_评委会打分
//        while(sc.hasNext()){
//            int n = sc.nextInt();
//            List<Double> list = new ArrayList<>();
//            for(int i=0;i<n;i++){
//                list.add(sc.nextDouble());
//            }
//            Collections.sort(list); //默认升序排序
//            list.remove(0);
//            list.remove(list.size()-1);
//            double sum = 0;
//            for (int j=0;j<list.size();j++){
//                sum+=list.get(j);
//            }
//            DecimalFormat df  = new DecimalFormat("0.00");
//            System.out.println(df.format(sum/list.size()));
//        }//        2015.偶数求和
//        while (sc.hasNext()) {
//            int n = sc.nextInt(), m = sc.nextInt();
//            List<Integer> list = new ArrayList<>();
//            for (int i = 1; i <=n; i++) {
//                list.add(i*2);
//            }
//            int sum =0;
//            int count = 0;
//            for (int j = 0; j <n; j++) {
//                sum += list.get(j);
//                count +=1;
//                if (count ==m || j==n-1){
//                    System.out.print(sum/count+" ");
//                    sum =0;
//                    count = 0;
//                }
//            }
//        }//  2016.数据的交换输出
//        while (sc.hasNext()) {
//            int n = sc.nextInt();
//            if(n==0)break;
//            int[] nums = new int [n];
//            int minIndex = 0;
//            int tmp;
//            for(int i = 0; i < n; i++) {
//                nums[i] = sc.nextInt();
//                if (nums[i]<nums[minIndex]){
//                    minIndex = i;
//                }
//            }
//            tmp = nums[minIndex];;
//            nums[minIndex] = nums[0];
//            nums[0]=tmp;
//            for(int i = 0; i < nums.length-1; i++) {
//                System.out.print(nums[i]+" ");
//            }
//            System.out.println(nums[nums.length-1]);
//        }//  2017.字符串统计
//        while (sc.hasNext()) {
//            int n = sc.nextInt();
//            sc.nextLine();
//            for (int i = 0; i < n; i++) {
//                String s = sc.nextLine();
//                int count =0;
//                for (int j = 0; j < s.length(); j++) {
//                    if (s.charAt(j)>=48 && s.charAt(j)<=57) {
//                        count +=1;
//                    }
//                }
//                System.out.println(count);
//            }
//        }//  2018.母牛的故事
//        long[] total = new long [54];
//        total[0]=1;
//        total[1]=2;
//        total[2]=3;
//        total[3]=4;
//        for (int i=4; i<54; i++){
//            total[i] = total[i-1]+total[i-3];
//        }
//        while (sc.hasNext()){
//            int n = sc.nextInt();
//            if(n==0)break;
//            System.out.println(total[n-1]);
//        }//  2019.数列有序!
//        while (sc.hasNext()) {
//            int n = sc.nextInt(), m = sc.nextInt();
//            if( n==0&& m==0)break;
//            List<Integer> list = new ArrayList<>();
//            for(int i=0; i<n; i++) {
//                list.add(sc.nextInt());
//            }
//            for(int j=0; j<m; j++) {
//                if(m>=list.get(j) && m<=list.get(j+1)) {
//                    list.add(j+1,m);
//                    break;
//                }
//            }
//            for(int k=0; k<list.size()-1; k++) {
//                System.out.print(list.get(k)+" ");
//            }
//            System.out.println(list.get(list.size()-1));
//        }//  2020.绝对值排序
//        while (sc.hasNext()) {
//            int n = sc.nextInt();
//            if(n==0)break;
//            int[] nums = new int [n];
//            for (int i = 0; i < n; i++) {
//                nums[i]=sc.nextInt();
//            }
//            int tmp;冒泡排序
//            for (int i = 0; i < n; i++) {
//                for (int j = 0; j < n-1-i; j++) {
//                    if(Math.abs(nums[j+1])>Math.abs(nums[j])){
//                        tmp=nums[j+1];
//                        nums[j+1]=nums[j];
//                        nums[j]=tmp;
//                    }
//                }
//            }
//            for (int k = 0; k < n-1; k++) {
//                System.out.print(nums[k]+" ");
//            }
//            System.out.println(nums[n-1]);
//        }//  2021.发工资咯:)
//        while (sc.hasNext()) {
//            int n = sc.nextInt();
//            sc.nextLine();
//            if (n == 0) break;
//            int [] nums = new int[n];
//            int [] coins = new int[] {100,50,10,5,2,1};
//            int count=0;
//            for(int i =0;i<n;i++) {
//                nums[i] = sc.nextInt();
//            }
//            for(int j =0;j<n;j++) {
//               while (nums[j]!=0){
//                   for(int k =0;k<coins.length;k++) {
//                       if(nums[j]>=coins[k]) {
//                           nums[j]-=coins[k];
//                           count++;
//                           break;
//                       }
//                   }
//               }
//            }
//            System.out.println(count);
//        }//  2022.海选女主角
//       存入行列数据
//        while (sc.hasNext()){
//            int m = sc.nextInt(),n = sc.nextInt();
//            int[][] nums = new int [m][n];
//            for(int i=0;i<m;i++){
//                for(int j=0;j<n;j++){
//                    nums[i][j] = sc.nextInt();
//                }
//            }
//            int max =0;
//            int maxX=0;
//            int maxY=0;
//            for(int i=0;i<m;i++){
//                for(int j=0;j<n;j++){
//                    if(Math.abs(nums[i][j])>Math.abs(max)){
//                        maxX = i+1;
//                        maxY = j+1;
//                        max = nums[i][j];
//                    }
//                }
//            }
//            System.out.println(maxX+" "+maxY+" "+max);
//        }//  2023.求平均成绩
//        while (sc.hasNext()) {
//            int n = sc.nextInt(), m = sc.nextInt();
//            sc.nextLine();
//            int [][] nums = new int [n][m];
//            double[] avgStu = new double[n];
//            double[] avgCla = new double[m];
//            double sumStu = 0;
//            double sumCla = 0;
//            int count = 0;
//            boolean flag = true;
//
//            DecimalFormat df = new DecimalFormat("0.00");
//
//            for (int i = 0; i < n; i++) {
//                sumStu = 0;
//                for (int j = 0; j < m; j++) {
//                    nums[i][j] = sc.nextInt();
//                    sumStu += nums[i][j];
//                }
//                avgStu[i] = (double) sumStu / m;
//            }
//
//            for (int j = 0; j < m; j++) {
//                sumCla = 0;
//                for (int i = 0; i < n; i++) {
//                    sumCla += nums[i][j];
//                }
//                avgCla[j] = (double) sumCla / n;
//            }
//            for (int i = 0; i < n; i++) {
//                flag = true;
//                for (int j = 0; j < m; j++) {
//                    if(nums[i][j] < avgCla[j]){
//                        flag = false;
//                        break;
//                    }
//                }
//                if(flag){
//                    count++;
//                }
//            }
//
//            for (int i = 0; i < n; i++) {
//                if(i == n - 1){
//                    System.out.printf("%.2f",avgStu[i]);  //结果保留两位小数
//                    System.out.println();
//                }else{
//                    System.out.printf("%.2f",avgStu[i]);
//                    System.out.print(" ");
//                }
//            }
//
//            for (int i = 0; i < m; i++) {
//                if(i == m - 1){
//                    System.out.printf("%.2f",avgCla[i]);
//                    System.out.println();
//                }else{
//                    System.out.printf("%.2f",avgCla[i]);
//                    System.out.print(" ");
//                }
//            }
//
//            System.out.println(count);
//            System.out.println();
//        }sc.close();}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com