国产探花免费观看_亚洲丰满少妇自慰呻吟_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); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳泉市| 广州市| 莒南县| 小金县| 宾阳县| 洛川县| 鲁甸县| 泽普县| 钟祥市| 山阴县| 来宾市| 闻喜县| 兴和县| 牙克石市| 姚安县| 亚东县| 乌审旗| 宿州市| 澎湖县| 汽车| 会昌县| 龙川县| 南通市| 迁西县| 布拖县| 乡宁县| 邯郸市| 宁安市| 玉田县| 方山县| 青田县| 白银市| 成武县| 金阳县| 沅陵县| 新巴尔虎左旗| 乳山市| 肥乡县| 克拉玛依市| 遂川县| 运城市|