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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

藍(lán)橋杯-尋找數(shù)列中最大數(shù)

2019-11-14 13:09:45
字體:
供稿:網(wǎng)友

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

按照題意,是應(yīng)該用數(shù)組來做的,后面用集合的方式就不能通過官方測試系統(tǒng)。(有點(diǎn)醉~~~)

//通過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); }}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌拉特中旗| 尉氏县| 瑞丽市| 玉屏| 云林县| 会理县| 通州区| 陵川县| 临漳县| 娄底市| 达拉特旗| 股票| 东城区| 息烽县| 梁平县| 海林市| 尚义县| 高阳县| 织金县| 浠水县| 会泽县| 裕民县| 都匀市| 六盘水市| 搜索| 云龙县| 通城县| 郑州市| 晋城| 高要市| 岳阳县| 岳西县| 平山县| 张掖市| 阿勒泰市| 依安县| 阆中市| 古交市| 乌兰浩特市| 黄浦区| 新营市|