fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. vector<pair<string, string>> v;
  4. int awal1 = 1;
  5. string check(string s, int awal, int akhir){
  6. int tengah = (awal+akhir)/2;
  7. bool temukan = false;
  8. if(v[tengah].first == s){
  9. return v[tengah].second;
  10. temukan = true;
  11. }
  12. else if(v[tengah].first > s){
  13. return check(s, awal, tengah-1);
  14. }
  15. else if(v[tengah].first < s){
  16. return check(s, tengah+1, akhir);
  17. }
  18. if(temukan == false) return "NIHIL";
  19. }
  20.  
  21. int main(){
  22. ios::sync_with_stdio(0);
  23. cin.tie(0);
  24. //freopen("input.txt", "r", stdin);
  25. //freopen("output.txt", "w", stdout);
  26. string s, s1, s2; vector<string> h;
  27. int n, p;
  28. cin >> n >> p;
  29. for(int i=1;i<=n;i++){
  30. cin >> s >> s1;
  31. v.push_back(make_pair(s, s1));
  32. }
  33. for(int j=1;j<=p;j++){
  34. cin >> s2;
  35. h.push_back(s2);
  36. }
  37. for(int i=1;i<=h.size();i++){
  38. cout << check(h[i], 1, v.size()) << "\n";
  39. }
  40. /*for(int i=0;i<v.size();i++){
  41. cout << v[i].first << " " << v[i].second << "\n";
  42. } */
  43. }
Time limit exceeded #stdin #stdout 5s 7258112KB
stdin
7 2
agung 572381
ani 111111
budi 222222
dengklek 696969
ganesh 987123
gareng 429088
hadi 682385
budi
nyancoder
stdout
Standard output is empty