Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Задания на работу с файлами
- #include <iostream>
- #include <fstream>
- #include <ctime>
- #include <cstdlib>
- #include <stdio.h>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main() {
- srand(time(0));
- //ЗАДАНИЕ НОМЕР 1
- int n[4000];
- fstream mydata;
- mydata.open("mydata.txt",ios::out);
- for (int i=0; i<4001; i++) {
- n[i] = 0 + rand() % 50;
- mydata << n[i] << " ";
- }
- mydata.close();
- //ЗАДАНИЕ НОМЕР 2
- int a[4001];
- int r = 0;
- int e = 0;
- int k = 0;
- int b[4];
- fstream report;
- report.open("report.txt",ios::out);
- mydata.open("mydata.txt",ios::in);
- for (int i=0; i<4001; i++) {
- mydata >> a[i];
- if (a[i] > 0)
- r++;
- }
- report << r << endl;
- for (int i=0; i<4001; i++) {
- if (a[i] % 3 == 0)
- e++;
- }
- report << e << endl;
- for (int i=0; i<4001; i++) {
- b[0] = (a[i] / 1000);
- b[1] = ((a[i] / 100) % 10);
- b[2] = ((a[i] / 10) % 10);
- b[3] = (a[i] % 10);
- 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]) )
- k++;
- }
- report << k;
- report << k << endl;
- cout << " ЗАДАНИЕ НОМЕР 3" << endl << endl;
- report << k << endl;
- report.close();
- mydata.close();
- int f[50][20];
- fstream matrice;
- matrice.open("matrice.txt",ios::out);
- mydata.open("mydata.txt",ios::in);
- for(int i=0;i<50;i++){
- for(int j=0;j<20;j++){
- mydata >> f[i][j];
- }
- }
- for (int i=0; i<=49; i++) {
- for (int j=0; j<=19; j++) {
- matrice << f[i][j] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement