国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

藍橋杯-尋找數列中最大數

2019-11-14 12:10:56
字體:
來源:轉載
供稿:網友

http://lx.lanqiao.cn/PRoblem.page?gpid=T111

按照題意,是應該用數組來做的,后面用集合的方式就不能通過官方測試系統。(有點醉~~~)

//通過import java.util.Scanner;public class Main { public static void main(String[] args){ int[] a = new int[1001]; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int max = 0; int t = 0; for (int i=0;i<n;i++){ a[i] = sc.nextInt(); if (i==0){ max = a[i]; t = i; }else if (i>0){ if (max <a[i]){ max = a[i]; t = i; } } } System.out.println(max +" " +t); }}//不能通過import java.util.HashMap;import java.util.Map;import java.util.Scanner;public class Main { public static void main(String[] args){ Map<Integer, Integer> map = new HashMap<Integer, Integer>(); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int max = 0; int t = 0; int key; for (key=0;key<n;key++){ int value = sc.nextInt(); map.put(key, value); if (key==0){ max = map.get(key); t=key; }else if(key>0){ if (max < map.get(key)){ max = map.get(key); t = key; } System.out.println("t="+t + "max="+max); } } System.out.println(max + " " +t); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 无为县| 行唐县| 鄄城县| 永清县| 京山县| 巧家县| 姜堰市| 永胜县| 石嘴山市| 衡东县| 全州县| 平果县| 铅山县| 临漳县| 乌鲁木齐县| 山西省| 甘谷县| 中山市| 公主岭市| 云和县| 靖州| 全南县| 樟树市| 岑巩县| 乐至县| 涞源县| 伊通| 瓮安县| 井冈山市| 天门市| 夹江县| 家居| 巴青县| 聊城市| 襄城县| 中西区| 宁强县| 岳西县| 确山县| 大埔县| 周口市|