题目搜集于各位前辈,侵删。
第一题
import java.util.Scanner;
public class c1101 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
String s = sc.nextLine();
String[] ss = s.split(" ");
for(int i = ss.length-1;i>=0;i--) {
if(i==ss.length-1) {
System.out.print(ss[i].toLowerCase());
}else {
System.out.print(" "+ss[i].toLowerCase());
}
}
System.out.println();
}
sc.close();
}
}
第二题
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class c1102 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t=0;t<T;t++) {
int n = sc.nextInt();
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
for(int i = 0;i<n;i++) {
String op = sc.next();
if(op.equals("Insert")) {
int key = sc.nextInt();
int value = sc.nextInt();
map.put(key, value);
}else {
int key = sc.nextInt();
if(!map.containsKey(key)) {
System.out.println("No result!");
}else{
int value = map.get(key);
System.out.println("name:"+key+" score:"+value);
}
}
}
}
sc.close();
}
}
第三题
6 5 5
0 1
0 2
1 3
2 4
2 5
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class c1103 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int l = sc.nextInt();
Node root = new Node(0);
for(int i = 0;i<n;i++) {
int fatherValue = sc.nextInt();
int sonValue = sc.nextInt();
Node father = search(root,fatherValue);
Node son = new Node(sonValue);
son.father = father;
father.sons.add(son);
}
double ans = 1;
Node node = search(root,l);
while(node.father!=null) {
ans*=node.father.sons.size();
node = node.father;
}
System.out.println(String.format("%.6f", 1.0/ans));
}
static class Node{
int value;
ArrayList<Node> sons = new ArrayList<Node>();
Node father = null;
public Node(int value) {
super();
this.value = value;
}
}
static Node search(Node root,int value) {
Queue<Node> queue = new LinkedList<Node>();
queue.add(root);
while(!queue.isEmpty()) {
Node node = queue.remove();
if(node.value==value) {
return node;
}else {
for(Node son:node.sons) {
queue.add(son);
}
}
}
return null;
}
}