Group Programming Skystair L2-019 quietly watched (25 points) (java)
Sina Weibo has a "quiet focus". A person that a user quietly Watches does not appear on the user's attention list, but the system will push the Weibo published by the person that he quietly watches to the user.Now let's do a web detective to pick out people who might be quietly watched by someone based on their attention list and how they like other users.
Input format:
Input first gives a user's list of concerns in the first line in the following format:
Number N User 1 User 2...User N
Where N is a positive integer of no more than 5,000, i(i=1,...N) is the ID of the user it is interested in, a 4-digit string of numbers and letters separated by spaces.
Then give the user's favorite information: first give a positive integer M not exceeding 10,000, then M lines, each line gives a user ID that is favored by the user and the number of times the user is favored (no more than 1,000), separated by a space.Note: The user ID is the unique identity of a user.Title guarantees that there are no duplicate users in the attention list and no duplicate users in the comments.
Output format:
We think people who get more favors from this user than their average number and aren't on their attention list are probably the ones they quietly follow.Based on this assumption, the alphabetical ascending output of user IDs may be the person they are quietly following, one ID per line.If there is no such person, output "Bing Mei You".
Input Sample 1:
10 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FatM LLao
8
Magi 50
Pota 30
LLao 3
Ammy 48
Dave 15
GAO3 31
Zoro 1
Cath 60
Output Sample 1:
Ammy
Cath
Pota
Input Sample 2:
11 GAO3 Magi Zha1 Sen1 Quan FaMK LSum Eins FatM LLao Pota
7
Magi 50
Pota 30
LLao 48
Ammy 3
Dave 15
GAO3 31
Zoro 29
Output Sample 2:
Bing Mei You
Data recorded with a linked list, the last test point timed out.TAT
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String fo[] = in.readLine().split(" "); Tool tool = new Tool(); int n = Integer.parseInt(in.readLine()); for(int i=0;i<n;i++) { String s[] = in.readLine().split(" "); Node node = new Node(s[0], s[1]); tool.add(node); } int average = tool.getSum()/n; ArrayList<String> id = new ArrayList<>(); ArrayList<String> realId = new ArrayList<>(); id = tool.getId(average); for(int i=0;i<id.size();i++) { int count = 0; for(int j=1;j<=Integer.parseInt(fo[0]);j++) { if(id.get(i).equals(fo[j])) { break; } count++; if(count == Integer.parseInt(fo[0])) { realId.add(id.get(i)); } } } String rId[] = new String[realId.size()]; for(int i=0;i<realId.size();i++) { rId[i] = realId.get(i); } Arrays.sort(rId); for(int i=0;i<rId.length;i++) { System.out.println(rId[i]); } if(rId.length==0) { System.out.println("Bing Mei You"); } } } class Tool { Node head = new Node("", ""); public void add(Node node) { Node temp = head; while(true) { if(temp.next == null) { break; } temp = temp.next; } temp.next = node; } public int getSum() { Node temp = head.next; int sum = 0; while(true) { if(temp == null) { break; } sum+=Integer.parseInt(temp.num); temp = temp.next; } return sum; } public ArrayList<String> getId(int average) { ArrayList<String> id = new ArrayList<>(); Node temp = head.next; while(true) { if(temp == null) { break; } if(Integer.parseInt(temp.num)>average) { id.add(temp.name); } temp = temp.next; } return id; } } class Node { String name; String num; Node next; public Node(String name, String num) { this.name = name; this.num = num; } }