Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("camioane.in");
  6. ofstream fout("camioane.out");
  7.  
  8. int n, m, s;
  9.  
  10. vector<pair<string, int>> camioane, drumuri;
  11.  
  12. bool comp(pair<string, int> a, pair<string, int> b){
  13.  
  14.     if(a.first.length() < b.first.length() || (a.first.length() == b.first.length() && a.first < b.first))
  15.  
  16.         return true;
  17.  
  18.     return false;
  19. }
  20.  
  21. void Citire(){
  22.  
  23.     fin >> n >> m;
  24.  
  25.     for(int i = 1; i <= n; i++){
  26.  
  27.         string x; fin >> x;
  28.  
  29.         drumuri.push_back(make_pair(x, i));
  30.     }
  31.  
  32.     sort(drumuri.begin(), drumuri.end(), comp);
  33.  
  34.     for(int i = 1; i <= m; i++){
  35.  
  36.         string x; fin >> x;
  37.  
  38.         camioane.push_back(make_pair(x, i));
  39.     }
  40.  
  41.     sort(camioane.begin(), camioane.end(), comp);
  42. }
  43.  
  44. int main(){
  45.  
  46.     Citire();
  47.  
  48.     int v[n + 1];
  49.  
  50.     while(!drumuri.empty()){
  51.  
  52.         if(camioane[0].first.length() < drumuri[0].first.length() || (camioane[0].first.length() == drumuri[0].first.length() && camioane[0].first <= drumuri[0].first)){
  53.  
  54.             v[drumuri[0].second] = camioane[0].second;
  55.  
  56.             camioane.erase(camioane.begin());
  57.  
  58.             drumuri.erase(drumuri.begin());
  59.  
  60.             s++;
  61.         }
  62.  
  63.         else{
  64.  
  65.             v[drumuri[0].second] = 0;
  66.  
  67.             drumuri.erase(drumuri.begin());
  68.         }
  69.     }
  70.  
  71.     fout << s << '\n';
  72.  
  73.     for(int i = 1; i <= n; i++)
  74.  
  75.         fout << v[i] << ' ';
  76.  
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement