Advertisement
evcamels

plot

Mar 27th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. // Задания на работу с файлами
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <ctime>
  6. #include <cstdlib>
  7. #include <stdio.h>
  8. #include <algorithm>
  9. #include <vector>
  10. using namespace std;
  11. int main() {
  12.     srand(time(0));
  13.    
  14.     //ЗАДАНИЕ НОМЕР 1
  15.    
  16.     int n[4000];
  17.     fstream mydata;
  18.     mydata.open("mydata.txt",ios::out);
  19.     for (int i=0; i<4001; i++) {
  20.         n[i] = 0 + rand() % 50;
  21.         mydata << n[i] << " ";
  22.     }
  23.     mydata.close();
  24.    
  25.     //ЗАДАНИЕ НОМЕР 2
  26.     int a[4001];
  27.     int r = 0;
  28.     int e = 0;
  29.     int k = 0;
  30.     int b[4];
  31.     fstream report;
  32.     report.open("report.txt",ios::out);
  33.     mydata.open("mydata.txt",ios::in);
  34.     for (int i=0; i<4001; i++) {
  35.         mydata >> a[i];
  36.       if (a[i] > 0)
  37.           r++;
  38.     }
  39.     report << r << endl;
  40.    
  41.     for (int i=0; i<4001; i++) {
  42.         if (a[i] % 3 == 0)
  43.            e++;
  44.        }
  45.     report << e << endl;
  46.    
  47.     for (int i=0; i<4001; i++) {
  48.         b[0] = (a[i] / 1000);
  49.         b[1] = ((a[i] / 100) % 10);
  50.         b[2] = ((a[i] / 10) % 10);
  51.         b[3] = (a[i] % 10);
  52.        
  53.         if ( (b[0] == b[1]) || (b[0] == b[2]) || (b[0] == b[3]) || (b[1] == b[2]) || (b[1] == b[3]) || (b[2] == b[3]) )
  54.             k++;
  55.     }
  56.     report << k;
  57.    
  58.     report << k << endl;
  59.    
  60.     cout << " ЗАДАНИЕ НОМЕР 3" << endl << endl;
  61.    
  62.    
  63.     report << k << endl;
  64.     report.close();
  65.     mydata.close();
  66.    
  67.     int f[50][20];
  68.  
  69.     fstream matrice;
  70.    
  71.     matrice.open("matrice.txt",ios::out);
  72.     mydata.open("mydata.txt",ios::in);
  73.    
  74.     for(int i=0;i<50;i++){
  75.         for(int j=0;j<20;j++){
  76.             mydata >> f[i][j];
  77.         }
  78.     }
  79.    
  80.     for (int i=0; i<=49; i++) {
  81.         for (int j=0; j<=19; j++) {
  82.             matrice << f[i][j] << " ";
  83.         }
  84.         cout << endl;
  85.     }
  86.     return 0;
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement