Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //lucasov
- #include <iostream>
- #include <cstdlib>
- #include <fstream>
- #include <ctime>
- #include <cmath>
- #include <cstring>
- using namespace std;
- int main(){
- srand(time(0));
- unsigned int start=rand()%(5-1+1)+1;
- unsigned int max=0;
- ofstream prvi("a_1.txt",ios::out);
- int br=0;
- while(max<pow(2,20)){
- max+=rand()%(5-1+1)+1;
- prvi<<max<<"\n";
- br++;
- }
- //----------------------------------------------
- prvi.close();
- int b1,b2,zbr=0;
- ifstream PRVI("a_1.txt");
- int br1=0;
- for(int i=0;i<br;i++){
- if(i==0){
- PRVI>>b1;
- }
- PRVI>>b2;
- zbr+=b2-b1;
- b1=b2;
- br1++;
- }
- float avg=zbr/br1; cout<<avg<<"\n";
- //----------------------------------------------
- //----------------------------------------------
- ofstream drugi("a_2.txt",ios::out);
- PRVI.clear();
- PRVI.seekg(0);
- int br2=0;
- for(int i=0;i<br;i++){
- if(i==0){
- PRVI>>b1;
- //drugi<<tmp;
- }
- PRVI>>b2;
- if((b2-b1)>avg){
- drugi<<b1<<"\n";
- //drugi<<b2<<"\n";
- }
- b1=b2;
- br2++;
- }
- PRVI.close();
- drugi.close();
- //----------------------------------------------
- ifstream DRUGI("a_2.txt");
- zbr=0;
- int br3=0;
- for(int i=0;i<br2;i++){
- if(i==0){
- DRUGI>>b1;
- }
- DRUGI>>b2;
- zbr+=b2-b1;
- b1=b2;
- br3++;
- }
- float avg2=zbr/br3; cout<<avg2<<"\n";
- DRUGI.clear();
- DRUGI.seekg(0);
- //-----------------------------------------------
- ofstream treci("a_3.txt",ios::out);
- br2=0;
- for(int i=0;i<br3;i++){
- if(i==0){
- DRUGI>>b1;
- }
- DRUGI>>b2;
- if((b2-b1)>avg2){
- treci<<b2<<"\n";
- }
- b1=b2;
- br2++;
- }
- DRUGI.close();
- treci.close();
- //------------------------------------------------
- ifstream TRECI("a_3.txt");
- zbr=0;
- br=0;
- for(int i=0;i<br2;i++){
- if(i==0){
- TRECI>>b1;
- }
- TRECI>>b2;
- zbr+=b2-b1;
- b1=b2;
- br++;
- }
- TRECI.close();
- float avg3=zbr/br;
- cout<<avg3;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement