fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main{
  5.  
  6. public static void main(String []args)throws Exception{
  7. String []st;
  8. String num;
  9. HashMap<String,Integer> h=new HashMap<String,Integer>();
  10. int n=Integer.parseInt(br.readLine());
  11. for(int i=0;i<n;i++){
  12. st=br.readLine().split(" ");
  13. num=(st[1]);
  14. if(st[0].equals("insert")){
  15.  
  16. if(h.get(num)==null){
  17. h.put(num, 1);
  18. }
  19. else{
  20. h.put(num, h.get(num)+1);
  21. }
  22.  
  23. check(h);
  24. }
  25. else if(st[0].equals("delete")){
  26.  
  27. if(h.get(num)!=null){
  28. if(h.get(num)==1){
  29. h.remove(num);
  30. }
  31. else{
  32. h.put(num, h.get(num)-1);
  33. }
  34. }
  35. check(h);
  36. }
  37. }
  38. }
  39.  
  40.  
  41. static void check(HashMap<String,Integer> h){
  42. int c2=0;
  43. for(String k:h.keySet()){
  44. if(h.get(k)>=2){
  45. c2++;
  46. }
  47.  
  48. }
  49. if(h.size()>1 && c2>=1){
  50. System.out.println("Both");
  51. }
  52. else if(h.size()>1){
  53. System.out.println("ManyOne");
  54. }
  55. else if(c2>=1){
  56. System.out.println("OneMany");
  57. }
  58. else{
  59. System.out.println("Niether");
  60. }
  61.  
  62. }
  63. }
Success #stdin #stdout 0.1s 320256KB
stdin
9
insert 1
insert 2
insert 1
insert 4
delete 1
delete 3
delete 2
delete 1
insert 4
stdout
Niether
ManyOne
Both
Both
ManyOne
ManyOne
ManyOne
Niether
OneMany