Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. //#define DEBUG //comment when you have to disable all debug macros.
  2. #include <iostream>
  3. #include <cstring>
  4. #include <sstream>
  5. #include <fstream>
  6. #include <cstdlib>
  7. #include <cstdio>
  8. #include <cmath>
  9. #include <vector>
  10. #include <set>
  11. #include <map>
  12. #include <bitset>
  13. #include <climits>
  14. #include <ctime>
  15. #include <algorithm>
  16. #include <functional>
  17. #include <stack>
  18. #include <queue>
  19. #include <list>
  20. #include <deque>
  21. #include <sys/time.h>
  22. #include <iomanip>
  23. #include <cstdarg>
  24. #include <utility> //std::pair
  25. #include <cassert>
  26.  
  27. using namespace std;
  28.  
  29. // Input macros
  30. #define s(n) scanf("%d",&n)
  31. #define sc(n) scanf("%c",&n)
  32. #define sl(n) scanf("%lld",&n)
  33. #define sf(n) scanf("%lf",&n)
  34. #define ss(n) scanf("%s",n)
  35.  
  36. //Pair macros
  37. #define mp make_pair // useful for working with pairs
  38. #define fi first
  39. #define se second
  40.  
  41. #define ll long long //data types used often, but you don't want to type them time by time_t
  42.  
  43. // Useful container manipulation / traversal macros
  44. #define forall(i,a,b) for(int i=a;i<b;i++)
  45. #define foreach(v, c) for( typeof( (c).begin()) v = (c).begin(); v != (c).end(); ++v)
  46. #define all(a) a.begin(), a.end()
  47. #define in(a,b) ( (b).find(a) != (b).end())
  48. #define pb push_back
  49.  
  50. #ifdef DEBUG
  51. #define debug(args...) {cerr << #args << ": ";dbg,args; cerr<<endl;}
  52. #else
  53. #define debug(args...) // Just strip off all debug tokens
  54. #endif
  55.  
  56. struct debugger
  57. {
  58. template<typename T> debugger& operator , (const T& v)
  59. {
  60. cerr<<v<<" ";
  61. return *this;
  62. }
  63. } dbg;
  64.  
  65. int main()
  66. {
  67. int t,i=0;
  68. string input;
  69. map<char, long long int> hashChar;
  70. cin >> t;
  71.  
  72.  
  73. while (i < t)
  74. {
  75. hashChar.clear();
  76. cin >> input;
  77. int currentIndex = 0;
  78. long long int p,q,current,hashIndex;
  79. bool charFound;
  80.  
  81. while (currentIndex < input.length())
  82. {
  83. if (hashChar.find(input[currentIndex]) != hashChar.end())
  84. hashChar[input[currentIndex]]++;
  85. else
  86. {
  87. hashChar[input[currentIndex]] = 1;
  88. }
  89.  
  90. currentIndex++;
  91. }
  92.  
  93. cin >> p >> q;
  94.  
  95. for (long long int a = 0; a < q; a++)
  96. {
  97. cin >> current;
  98.  
  99. hashIndex = 1;
  100. charFound = false;
  101.  
  102. for (int b = 0; b < 256; b++)
  103. {
  104. if (hashChar.find(b) != hashChar.end())
  105. {
  106. hashIndex += hashChar[b]*p;
  107. if (hashIndex > current)
  108. {
  109. printf("%c\n", b);
  110. charFound = true;
  111. break;
  112. }
  113. }
  114. }
  115.  
  116. if (!charFound)
  117. {
  118. printf("-1\n");
  119. }
  120. }
  121.  
  122. i++;
  123.  
  124. }
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement