evcamels

plot

Mar 27th, 2021
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 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 i;
  17.     int n[4000];
  18.     fstream mydata;
  19.     mydata.open("mydata.txt",ios::out);
  20.     for (i=0; i<4001; i++) {
  21.         n[i] = 0 + rand() % 50;
  22.         mydata << n[i] << " ";
  23.     }
  24.     mydata.close();
  25.    
  26.     //ЗАДАНИЕ НОМЕР 2
  27.     int a[i];
  28.     int q;
  29.     int r = 0;
  30.     int e = 0;
  31.     int k = 0;
  32.     int b[3];
  33.     fstream report;
  34.     report.open("report.txt",ios::out);
  35.     mydata.open("mydata.txt",ios::in);
  36.     for (i=0; i<4001; i++) {
  37.         mydata >> a[i];
  38.       if (a[i] > 0)
  39.           r++;
  40.     }
  41.     report << r << endl;
  42.    
  43.     for (i=0; i<4001; i++) {
  44.         if (a[i] % 3 == 0)
  45.            e++;
  46.        }
  47.     report << e << endl;
  48.    
  49.     for (i=0; i<4001; i++) {
  50.         b[0] = (a[i] / 1000);
  51.         b[1] = ((a[i] / 100) % 10);
  52.         b[2] = ((a[i] / 10) % 10);
  53.         b[3] = (a[i] % 10);
  54.        
  55.         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]) )
  56.             k++;
  57.     }
  58.     report << k;
  59.    
  60.     report << k << endl;
  61.    
  62.     cout << " ЗАДАНИЕ НОМЕР 3" << endl << endl;
  63.    
  64.    
  65.     report << k << endl;
  66.     report.close();
  67.     mydata.close();
  68.    
  69.     int f[50][20];
  70.  
  71.     fstream matrice;
  72.    
  73.     matrice.open("matrice.txt",ios::out);
  74.     mydata.open("mydata.txt",ios::in);
  75.    
  76.     for(int i=0;i<50;i++){
  77.         for(int j=0;j<20;j++){
  78.             mydata >> f[i][j];
  79.         }
  80.     }
  81.    
  82.     for (int i=0; i<=49; i++) {
  83.         for (int j=0; j<=19; j++) {
  84.             matrice << f[i][j] << " ";
  85.         }
  86.         cout << endl;
  87.     }
  88.     return 0;
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment