Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef vector<int> vi;
  7. typedef pair<int, int> pii;
  8.  
  9. #define f0rn(i, a, b) for (int i=a; i<(b); i++)
  10. #define forn(i,n) for(int i = 0; i < n; i++)
  11.  
  12. #define mp make_pair
  13. #define pb push_back
  14. #define ff first
  15. #define ss second
  16.  
  17. const int MOD = 1000000007;
  18.  
  19. vector< pair<string, string> > arr;
  20.  
  21. int main() {
  22. ifstream fin("citystate.in");
  23. ofstream fout("citystate.out");
  24. int n; fin >> n;
  25. forn(i,n) {
  26. string a, b; fin >> a >> b;
  27. arr.pb(mp(a.substr(0,2),b));
  28. }
  29. fin.close();
  30. sort(arr.begin(),arr.end());
  31. string search[n];
  32. for(int i = 0; i < n; i++) {
  33. search[i] = arr[i].first;
  34. }
  35. int cnt = 0;
  36. for(int i = 0; i < n; i++) {
  37. int ind = lower_bound(search,search+n,arr[i].second)-search;
  38. if(ind != n) {
  39. if(arr[ind].second == arr[i].first) {
  40. //cout << arr[ind].first << " " << arr[ind].second;
  41. cnt++;
  42. }
  43. }
  44. int t1 = ind+1;
  45. while(t1 < n) {
  46. if(arr[t1].second == arr[i].first && arr[t1].first == arr[i].second) {
  47. //cout << arr[t1].first << " " << arr[t1].second << endl;
  48. cnt++;
  49. }
  50. t1++;
  51. }
  52. while(ind >= 0) {
  53. if(arr[ind].second == arr[i].first && arr[ind].first == arr[ind].second) {
  54. //cout << arr[ind].first << " " << arr[ind].second << endl;
  55. cnt++;
  56. }
  57. ind--;
  58. }
  59. }
  60. fout << cnt/2;
  61. fout.close();
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement