Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("camioane.in");
- ofstream fout("camioane.out");
- int n, m, s;
- vector<pair<string, int>> camioane, drumuri;
- bool comp(pair<string, int> a, pair<string, int> b){
- if(a.first.length() < b.first.length() || (a.first.length() == b.first.length() && a.first < b.first))
- return true;
- return false;
- }
- void Citire(){
- fin >> n >> m;
- for(int i = 1; i <= n; i++){
- string x; fin >> x;
- drumuri.push_back(make_pair(x, i));
- }
- sort(drumuri.begin(), drumuri.end(), comp);
- for(int i = 1; i <= m; i++){
- string x; fin >> x;
- camioane.push_back(make_pair(x, i));
- }
- sort(camioane.begin(), camioane.end(), comp);
- }
- int main(){
- Citire();
- int v[n + 1];
- while(!drumuri.empty()){
- if(camioane[0].first.length() < drumuri[0].first.length() || (camioane[0].first.length() == drumuri[0].first.length() && camioane[0].first <= drumuri[0].first)){
- v[drumuri[0].second] = camioane[0].second;
- camioane.erase(camioane.begin());
- drumuri.erase(drumuri.begin());
- s++;
- }
- else{
- v[drumuri[0].second] = 0;
- drumuri.erase(drumuri.begin());
- }
- }
- fout << s << '\n';
- for(int i = 1; i <= n; i++)
- fout << v[i] << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement