Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: main.cpp
- * Author: kaucsenta
- *
- * Created on 2013. november 1., 0:19
- */
- #include <iostream>
- #include <cstdlib>
- #include <fstream>
- #include <sstream>
- #include <vector>
- using namespace std;
- int main() {
- srand (time(NULL));
- int N;
- int newitem;
- vector<int> array;
- string file;
- cout<<"Hany elemu random int listat akarsz?"<<endl;
- cin>>N;
- file="random"+static_cast<ostringstream*>( &(ostringstream() << N) )->str()+".txt";
- ofstream myfile(file.c_str());
- for(int i=0;i<N;i++){
- bool unique;
- do
- {
- unique=true;
- newitem=rand()%N;
- for(int i1=0;i1<i;i1++)
- {
- if(array[i1]==newitem)
- {
- unique=false;
- break;
- }
- }
- }while(!unique);
- array.push_back(newitem);
- cout<<array[i]<<endl;
- }
- N=array.size();
- for( vector<int>::const_iterator i = array.begin(); i != array.end()-1; ++i)
- myfile<< *i <<endl;
- myfile<<array[N-1];
- myfile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment