• mit java open course assignment #2


    package come;
    
    public class Marothon {
    
        public static void FirstName(String[] args1,int[] args2){
            int MinIndex,MinTime,i;
            MinTime = 10000;
            MinIndex = 0;
            for(i = 0; i < 16; i++){
                if (args2[i] < MinTime){
                    MinTime = args2[i];
                    MinIndex = i; 
                }
            }
            System.out.println(args1[MinIndex] + " "+MinTime);
        }
        public static void SecondName(String[] args1, int[] args2){
            int SmallIndex,SmallerIndex,Small,Smaller,i;
            Small = 10000;
            Smaller = 10000;
            SmallerIndex = 100;
            SmallIndex =101;
            for(i = 0; i<16; i++){
                if(args2[i] < Small && args2[i] > Smaller){
                    Small = args2[i];
                    SmallIndex = i;
                }else if(args2[i] < Smaller){
                    Small = Smaller;
                    Smaller = args2[i];
                    SmallIndex = SmallerIndex;
                    SmallerIndex = i;
                }
            }
            System.out.println(args1[SmallIndex] + " " + args2[SmallIndex]);
        }
        public static void main(String[] args){
            // TODO Auto-generated method stub
            String[] names = {"Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt", "Alex",
                    "Emma", "John", "James", "Jane", "Emily", "Daniel", "Neda",
                    "Aaron", "Kate"};
            int[] times = {341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299,
                    343, 317, 265};
            SecondName(names,times);
    }
    }
    View Code

    SecondName函数只遍历了一次数组,大大提升了之前想用FirstName遍历一次后用if避开最小的来做,不过就要遍历两次,哈哈哈,不错

  • 相关阅读:
    hdu 2709 Sumsets
    hdu 2004 成绩转换
    hihocoder 1043 完全背包
    hihocoder 1038 01背包
    hihocoder 1066 无间道之并查集
    并查集小结
    hdu 1232 畅通工程
    并查集学习2
    并查集知识学习
    js 禁止表单提交的方法(文件上传)
  • 原文地址:https://www.cnblogs.com/gabygoole/p/4802817.html
Copyright © 2020-2023  润新知