Advertisement
Guest User

olymp day 1

a guest
Mar 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <unordered_map>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     FILE *f, *d;
  11.     f = fopen("in.txt", "r");
  12.  
  13.     d = fopen("OUT.TXT", "w");
  14.  
  15.     unordered_map<char, int> map;
  16.     vector<char> str1;
  17.  
  18.     char sym;
  19.  
  20.     bool map_work = true;
  21.     while (true) {
  22.         if (feof(f)) { break; }
  23.         sym = fgetc(f);
  24.  
  25.         cout << sym << endl;
  26.         if (sym == '\n') {
  27.             map_work = false;
  28.         }
  29.  
  30.         if (map_work) {
  31.             if (map.find(sym) == map.end()) {
  32.                 map.insert(pair<char, int>(sym, 1));
  33.                 str1.push_back(sym);
  34.             } else { map[sym] += 1; }
  35.  
  36.         } else if (map.find(sym) != map.end()) { map[sym] -= 1; }
  37.     }
  38.  
  39.     bool good = true;
  40.     for (int i = 0; i < str1.size(); i++) {
  41.         if (map[str1[i]] > 0) {
  42.             good = false;
  43.             break;
  44.         };
  45.     }
  46.  
  47.     if (good) { fprintf(d, "Да"); }
  48.     else { fprintf(d, "Нет"); }
  49.  
  50.     fclose(f);
  51.     fclose(d);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement