fork download
  1. import java.io.*;
  2. import java.math.*;
  3. import java.util.*;
  4. class Solution
  5. {
  6. public static void main (String[] args)throws IOException
  7. {
  8. try{
  9. int t=Integer.parseInt(br.readLine());
  10. while(t!=0)
  11. {
  12. int n=Integer.parseInt(br.readLine());
  13. String a[]=new String[n];
  14. int vote[]=new int[n];
  15. int i,j;
  16. String ip[]=new String[2];
  17. for(i=0;i<n;i++)
  18. {
  19. ip=br.readLine().split(" ");
  20. a[i]=ip[0];
  21. char ch=ip[1].charAt(0);
  22. if(ch=='+')
  23. vote[i]=1;
  24. else
  25. vote[i]=-1;
  26. }
  27. int lastpos=0;
  28. int track[]=new int[n];
  29. for(i=0;i<n;i++)
  30. {
  31. for(j=0;j<n;j++)
  32. {
  33. if(track[i]==0 && a[i].equals(a[j])==true)
  34. {
  35. if(i!=j)
  36. track[lastpos]=1;
  37. lastpos=j;
  38. }
  39. }
  40. track[lastpos]=100000;
  41. }
  42. int count=0;
  43. for(i=0;i<n;i++)
  44. {
  45. if(track[i]==100000)
  46. count=count+vote[i];
  47. }
  48. System.out.println(count);
  49. t--;
  50. }
  51. }catch(Exception e)
  52. {return;}
  53. }
  54. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
Standard output is empty