mhb233 2019-11-07 17:09 采纳率: 0%
浏览 432

pat官网与牛客网两者结果对比

乙级 1028 人口普查 (20 分)这个题
在pat官网中,
编程提交,结果如下:
图片说明

在牛客网中,提交结果如下:

图片说明
运行超时我就不说了,可是为什么牛客网通过了二官网却有一个错误?求告知。
下面是我的代码:

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();//定义人数
        String str[][]=new String[n][2];//创建n人的资料数组
        int str1[]=new int[n];//创建保存出生年月的数组
        int temp1=100000000;//最小岁数的人,所以初值应大于20140906
        int temp2=0;//最大岁数的人,所以temp1初值为0
        int m1=0;//最大岁数人对应的位置,初值为0
        int m2=0;//最小岁数人对应的位置,初值为0
        int temp=0;//合理生日人数
        for(int i=0;i<n;i++) {//输入名字,出生年月

            for(int j=0;j<2;j++){
                str[i][j]=sc.next();
            }   
            String st=str[i][1].substring(0, 4)+str[i][1].substring(5, 7)+str[i][1].substring(8, 10);
            str1[i]=(int)Double.parseDouble(st);//将出生年月去掉'/'后赋值
            if(str1[i]>=18140906&&str1[i]<=20140906) {//超过200岁的和未出生的是不合理的,今天是2014/09/06
                    temp++; 
                if(temp1>=str1[i]) {//找出最大岁数的人
                    temp1=str1[i];//将生日赋值给temp1
                    m1=i;//将位置保存在m1中
                }
                if(temp2<=str1[i]) {//找出最小岁数的人
                    temp2=str1[i];//将生日赋值给temp2
                    m2=i;//将位置保存在m2中
                }
            }   
        }
        System.out.print(temp);
        System.out.print(" ");//空格间隔
        System.out.print(str[m1][0]);//岁数最大得人
        System.out.print(" ");//空格间隔
        System.out.print(str[m2][0]);//岁数最小的人
    }
}

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2019-11-08 17:15
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog