Advertisement
Guest User

Cues d'un supermercat (1)

a guest
May 24th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4. #include <queue>
  5. using namespace std;
  6.  
  7. int main() {
  8.   int n;
  9.   string s;
  10.   getline(cin, s);
  11.   istringstream ss(s);
  12.   ss >> n;
  13.   vector<queue<string> > v(n);
  14.   string linia, nom;
  15.   for (int i = 0; i < n; ++i) {
  16.     getline(cin, linia);
  17.     istringstream lin(linia);
  18.     while (lin >> nom) v[i].push(nom);
  19.   }
  20.  
  21.   string activity;
  22.   int cua;
  23.   cout << "SORTIDES" << endl << "--------" << endl;
  24.   while (cin >> activity) {
  25.     if (activity == "SURT") {
  26.       cin >> cua;
  27.       cua--;
  28.       if (cua >= 0 and cua < n) {
  29.     if (not v[cua].empty()) {
  30.       cout << v[cua].front() << endl;
  31.       v[cua].pop();
  32.     }
  33.       }
  34.     }
  35.     else if (activity == "ENTRA") {
  36.       cin >> nom >> cua;
  37.       cua--;
  38.       if (cua >= 0 and cua < n) {
  39.     v[cua].push(nom);
  40.       }
  41.     }
  42.   }
  43.   cout << endl << "CONTINGUTS FINALS" << endl << "-----------------" << endl;
  44.   for (int i = 0; i < n; ++i) {
  45.     cout << "cua " << i+1 << ":";
  46.     while (not v[i].empty()) {
  47.       cout << " " << v[i].front();
  48.       v[i].pop();
  49.     }
  50.     cout << endl;
  51.   }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement