日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

hackerrank Java Data Structures

發布時間:2023/12/20 java 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hackerrank Java Data Structures 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

地址:https://www.hackerrank.com/domains/java/java-data-structure

題目https://www.hackerrank.com/challenges/java-list

import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*;public class Solution {public static void main(String[] args) {/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scanner in = new Scanner(System.in);int n = in.nextInt();LinkedList<Integer> l = new LinkedList<Integer>();for(int i = 0;i < n;i++)l.add(in.nextInt());int q = in.nextInt();while(q-- > 0){String op = in.next();if(op.equals("Insert")){int x = in.nextInt(),y = in.nextInt();l.add(x,y);}else{int x = in.nextInt();l.remove(x);}}for(int x : l)System.out.print(x + " "); } }

題目:https://www.hackerrank.com/challenges/phone-book
題意:使用map
思路:以前好像沒怎么用過.nextLine()
.nextLine()用來讀入一行數據,這個和C++已經取消的gets相似,都會讀入換行,如果使用前有讀入數據的話,提前讀入空行.nextLine() 防止影響后面的讀入。
代碼:

//Complete this code or write your own from scratch import java.util.*; import java.io.*;class Solution{public static void main(String []argh){Scanner in = new Scanner(System.in);int n = in.nextInt();in.nextLine();HashMap<String,Integer> mp = new HashMap<String,Integer>();while(n-- > 0){String name = in.nextLine();int number = in.nextInt();mp.put(name, number);in.nextLine();}while(in.hasNext()){String name = in.nextLine();if(mp.containsKey(name))System.out.println(name + "=" + mp.get(name));elseSystem.out.println("Not found");}} }

題目:https://www.hackerrank.com/challenges/java-stack/problem
代碼:

import java.util.*; class Solution{public static void main(String []argh){Scanner in = new Scanner(System.in);while(in.hasNext()){String s = in.next();Stack<Character> st = new Stack<Character>();for(int i = 0;i < s.length();i++){if(!st.empty()){switch(s.charAt(i)){case ')':if(st.peek() == '(')st.pop();break;case ']':if(st.peek() == '[')st.pop();break;case '}':if(st.peek() == '{')st.pop();break;default:st.push(s.charAt(i));}}elsest.push(s.charAt(i));}if(st.empty())System.out.println("true");elseSystem.out.println("false");}} }

題目:https://www.hackerrank.com/challenges/java-hashset/problem
代碼:

總結

以上是生活随笔為你收集整理的hackerrank Java Data Structures的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。