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

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

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

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

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); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金平| 洪江市| 阜平县| 阳江市| 石狮市| 喀喇沁旗| 托里县| 开封县| 九江县| 克山县| 南丹县| 合山市| 永康市| 陕西省| 张家口市| 秦皇岛市| 深水埗区| 江西省| 常山县| 洛川县| 望奎县| 乌鲁木齐县| 永年县| 隆德县| 茌平县| 东乡族自治县| 赤水市| 临沂市| 罗平县| 陵川县| 关岭| 堆龙德庆县| 桂阳县| 郴州市| 慈溪市| 临泽县| 沧源| 介休市| 磐石市| 宜兴市| 建平县|