soss_nom

6 zadaniy ot A.M.

Nov 28th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.20 KB | None | 0 0
  1. //МУЗЕЙ
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <fstream>
  6. using namespace std;
  7. int main()
  8. {
  9.     string temp;
  10.     vector <int> time;
  11.     ifstream in("INPUT.txt");
  12.     getline(in, temp);
  13.     int n = stoi(temp);
  14.     while (getline(in, temp))
  15.     {
  16.         time.push_back((temp[0] - '0') * 1000 + (temp[1] - '0') * 100 + (temp[3] - '0') * 10 + (temp[4] - '0'));
  17.         time.push_back((temp[6] - '0') * 1000 + (temp[7] - '0') * 100 + (temp[9] - '0') * 10 + (temp[10] - '0'));
  18.     }
  19.     in.close();
  20.     int k = 0, kmax = 0;
  21.     for (int i = 1; i < 2 * n; i += 2)
  22.     {
  23.         for (int j = i + 1; j < 2 * n; j += 2)
  24.             if (time[i] > time[j])
  25.                 k++;
  26.         if (k > kmax)
  27.             kmax = k;
  28.         k = 0;
  29.     }
  30.     ofstream out("OUTPUT.txt");
  31.     out << kmax + 1;
  32.     out.close();
  33.     return 0;
  34. }
  35.  
  36. //ЗМЕЙКА
  37. #include <iostream>
  38. #include <string>
  39. #include <fstream>
  40. using namespace std;
  41. int main()
  42. {
  43.     string temp;
  44.     ifstream in("INPUT.txt");
  45.     getline(in, temp);
  46.     in.close();
  47.     int n = stoi(temp), c = 1, i = 0, j = 0;
  48.     int** arr = new int* [n];
  49.     for (int i = 0; i < n; i++)
  50.         arr[i] = new int[n];
  51.     arr[0][0] = c; c++;
  52.     bool left = true, up = true;
  53.     while (c != n * n)
  54.     {
  55.         if (up)
  56.         {
  57.             if (left)i++;
  58.             else j++;
  59.             arr[i][j] = c; c++;
  60.             while (left ? i != 0 : j != n - 1)
  61.             {
  62.                 i--; j++;
  63.                 arr[i][j] = c; c++;
  64.             }
  65.             up = !up;
  66.         }
  67.         else
  68.         {
  69.             if (left)j++;
  70.             else i++;
  71.             arr[i][j] = c; c++;
  72.             while (left ? j != 0 : i != n - 1)
  73.             {
  74.                 i++; j--;
  75.                 arr[i][j] = c; c++;
  76.             }
  77.             up = !up;
  78.         }
  79.         if (i == 0 && j == n - 1 || i == n - 1 && j == 0) left = false;
  80.     }
  81.     arr[n - 1][n - 1] = c;
  82.     ofstream out("OUTPUT.txt");
  83.     for (i = 0; i < n; i++)
  84.     {
  85.         for (j = 0; j < n; j++)
  86.         {
  87.             out << arr[i][j] << " ";
  88.         }
  89.         out << endl;
  90.     }
  91.     out.close();
  92.     for (int i = 0; i < n; i++)
  93.         delete[] arr[i];
  94.     delete[]arr;
  95.     return 0;
  96. }
  97.  
  98. //РАСПАКОВКА СТРОКИ
  99. #include <iostream>
  100. #include <string>
  101. #include <fstream>
  102. using namespace std;
  103. int main()
  104. {
  105.     string str;
  106.     ifstream in("INPUT.txt");
  107.     ofstream out("OUTPUT.txt");
  108.     getline(in, str);
  109.     in.close();
  110.     for (int i = 0, ti = 0, num = 0, discharge = 1, k = 0; i < str.length(); i++)
  111.     {
  112.         if (str[i] >= 'A' && str[i] <= 'Z')
  113.         {
  114.             ti = i - 1;
  115.             while (ti >= 0 && (str[ti] < 'A' || str[ti] > 'Z'))
  116.             {
  117.                 num += (str[ti] - '0') * discharge;
  118.                 discharge *= 10;
  119.                 ti--;
  120.             }
  121.             discharge = 1;
  122.             if (num == 0) num++;
  123.             for (int j = 0; j < num; j++)
  124.             {
  125.                 if (k % 40 == 0 && k != 0) out << endl;
  126.                 out << str[i];
  127.                 k++;
  128.             }
  129.             num = 0;
  130.         }
  131.     }
  132.     out.close();
  133.     return 0;
  134. }
  135.  
  136. //ПРЕДСТАВЛЕНИЕ ЧИСЕЛ
  137. #include <iostream>
  138. #include <string>
  139. #include <fstream>
  140. using namespace std;
  141. int nod(int m, int n)
  142. {
  143.     if (m > n)
  144.         m = m - n;
  145.     else
  146.         n = n - m;
  147.     if (m == n) return m;
  148.     else nod(m, n);
  149. }
  150. void rec(int x, int y)
  151. {
  152.     static int maxnod = 1, mx = x, my = y;
  153.     ofstream out("OUTPUT.txt");
  154.     if ((x + y) % 2 == 0)
  155.     {
  156.         out << (x + y) / 2 << " " << (x + y) / 2;
  157.         out.close();
  158.         return;
  159.     }
  160.     int curnod = nod(x, y);
  161.     if (curnod > maxnod)
  162.     {
  163.         maxnod = curnod;
  164.         mx = x;
  165.         my = y;
  166.     }
  167.     x--; y++;
  168.     if (x == 0)
  169.     {
  170.         out << mx << " " << my;
  171.         out.close();
  172.         return;
  173.     }
  174.     else rec(x, y);
  175. }
  176. int main()
  177. {
  178.     int num;
  179.     ifstream in("INPUT.txt");
  180.     in >> num;
  181.     in.close();
  182.     rec(num - 1, 1);
  183.     return 0;
  184. }
  185.  
  186. //ПОДАРКИ ДЕДА МОРОЗА
  187. #include <iostream>
  188. #include <fstream>
  189. using namespace std;
  190. void recz(int x, int y, int z, int w, int curw, int& k)
  191. {
  192.     if (curw == w)
  193.     {
  194.         k++;
  195.         return;
  196.     }
  197.     else if (curw > w) return;
  198.     recz(x, y, z, w, curw + z, k);
  199. }
  200. void recy(int x, int y, int z, int w, int curw, int& k)
  201. {
  202.     if (curw == w)
  203.     {
  204.         k++;
  205.         return;
  206.     }
  207.     else if (curw > w) return;
  208.     recy(x, y, z, w, curw + y, k);
  209.     recz(x, y, z, w, curw + z, k);
  210. }
  211. void recx(int x, int y, int z, int w,int curw , int &k)
  212. {
  213.     if (curw == w)
  214.     {
  215.         k++;
  216.         return;
  217.     }
  218.     else if (curw > w) return;
  219.     recx(x, y, z, w, curw+x, k);
  220.     recy(x, y, z, w, curw+y, k);
  221.     recz(x, y, z, w, curw+z, k);
  222. }
  223. int main()
  224. {
  225.     int k = 0,x,y,z,w;
  226.     ifstream in("INPUT.txt");
  227.     ofstream out("OUTPUT.txt");
  228.     in >> x;
  229.     in >> y;
  230.     in >> z;
  231.     in >> w;
  232.     in.close();
  233.     recx(x, y, z, w, 0, k);
  234.     out << k;
  235.     out.close();
  236.     return 0;
  237. }
Advertisement
Add Comment
Please, Sign In to add comment