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

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

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

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

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); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大渡口区| 文山县| 石门县| 长沙市| 兴宁市| 府谷县| 河南省| 宾川县| 文登市| 封丘县| 霍林郭勒市| 旬阳县| 平利县| 民权县| 巴里| 大连市| 灵寿县| 台中市| 芜湖县| 盐山县| 宜昌市| 合江县| 嘉祥县| 濉溪县| 洛宁县| 奈曼旗| 鹤岗市| 大余县| 郯城县| 乐平市| 台北县| 双牌县| 治县。| 土默特右旗| 大新县| 义乌市| 清流县| 霞浦县| 长宁区| 汨罗市| 梅州市|