fork(5) download
  1.  
  2. #include<iostream>
  3. #include<map>
  4. #include<string>
  5. #include<cstring>
  6. #include<cstdio>
  7. #include<vector>
  8. #include<algorithm>
  9. #include<string>
  10. #include<set>
  11. #include<queue>
  12. using namespace std;
  13. vector<string>v2[101];
  14. struct store
  15. {
  16. string name;
  17. long long value;
  18. store(string name, long long value)
  19. {
  20. this->name = name;
  21. this->value = value;
  22.  
  23. }
  24. bool operator < (const store &p) const
  25. {
  26. if (p.value < value)
  27. return p.value<value;
  28. else
  29. return false;
  30. }
  31.  
  32. };
  33. int main()
  34. {
  35. map<string, long long>v;
  36. map<string, long long>v1;
  37. map<long long, string>v3;
  38. map<string, long long>v4;
  39. map<string, long long>v5;
  40. vector<store> out;
  41. set<string>s;
  42. char name[1000];
  43. string z, x;
  44. long long time = 0, i, j, check;
  45. while (gets(name))
  46. {
  47. if (name[0] == '0' &&strlen(name) == 1)
  48. break;
  49. if (name[0] == '1'&&strlen(name)==1)
  50. {
  51.  
  52. if (v1[name] == 0 && strlen(name) == 1)
  53. {
  54. v1[name] = ++time;
  55. v3[time] = name;
  56.  
  57.  
  58. }
  59. v5.clear();
  60. long long co = 0;
  61. for (i = 1; i <= time - 1; i++)
  62. {
  63. co = 0;
  64. for (j = 0; j < v2[i].size(); j++)
  65. {
  66. if (v[v2[i][j]] == 1 && v5[v2[i][j]] == 0)
  67. {
  68.  
  69. co = co + 1;
  70. v5[v2[i][j]] = 1;
  71. }
  72.  
  73. }
  74. v4[v3[i]] = co;
  75.  
  76. }
  77.  
  78. map<string, long long>::iterator it;
  79. for (it = v4.begin(); it != v4.end(); it++)
  80. {
  81. out.push_back(store(it->first, it->second));
  82.  
  83. }
  84. sort(out.begin(), out.end());
  85. for (i = 0; i < out.size(); i++)
  86. {
  87. cout << out[i].name << " " << out[i].value << "\n";
  88.  
  89. }
  90.  
  91. time = 0;
  92. for (i = 0; i <= time+1; i++)
  93. v2[i].clear();
  94. v.clear();
  95. v1.clear();
  96. v3.clear();
  97. v4.clear();
  98. v5.clear();
  99. out.clear();
  100. s.clear();
  101. time = 0;
  102. co = 0;
  103. }
  104. else{
  105. z = name;
  106. transform(z.begin(), z.end(), z.begin(), ::toupper);
  107. if (z == name)
  108. {
  109. x = name;
  110. if (v1[name] == 0)
  111. {
  112. v1[name] = ++time;
  113. v3[time] = name;
  114.  
  115. }
  116. v5.clear();
  117.  
  118.  
  119. }
  120. else{
  121. if (v5[name] == 0)
  122. {
  123.  
  124. v[name] = v[name] + 1;
  125. v5[name] = 1;
  126. }
  127. long long lol = v1[x];
  128. v2[lol].push_back(name);
  129.  
  130. }
  131.  
  132.  
  133.  
  134. }
  135.  
  136. }
  137.  
  138. }
Success #stdin #stdout 0s 3300KB
stdin
 ROBOTS
me
and
noone
LINUX
isthebest
isthebest
noone
ELECTRONIX PROJECT
hateit
burned
hateit
hateit
noone
C PROJECT
iscool
iamhere
hellworld
linux
gui
iscool
me
THIS IS THE LAST
helloworld
thisisme
hopeyougetaccepted
1
AB
AA
1
AA
x
c
BA
x
C
1
AA
BA
C
1
ROBOTS
me
and
noone
LINUX
isthebest
noone
noone
iamhere
ELECTRONIX PROJECT
isthebest
hateit
burned
hateit
hateit
noone
C PROJECT #2
iscool
iamhere
hellworld
linux
gui
iscool
me
THIS IS THE LAST
helloworld
thisisme
hopeyougetaccepted
gui
1
A
x
x
x
B
x
x
x
C
x
x
x
1
0
stdout
C PROJECT 5
THIS IS THE LAST 3
ELECTRONIX PROJECT 2
 ROBOTS 1
LINUX 1
AA 0
AB 0
AA 1
BA 0
C 0
AA 0
BA 0
C 0
C PROJECT #2 3
THIS IS THE LAST 3
ELECTRONIX PROJECT 2
ROBOTS 1
LINUX 0
A 0
B 0
C 0