Coding/Python 삽질기2012. 11. 7. 01:31

#Python Version

import random

result = []

while ( len(result) < 10000 ):

    x = random.randint(1, 10001)

    y = random.randint(1, 10001)

    result.append( (x, y) )

    result = list(set(result))


/* C++ Version */
#include <iostream>
#include <fstream>
#include <ctime>
#include <cstdlib>
#include <set>
using namespace std;

typedef pair<int, int> Point2D;

class IsSame {
public:
       bool operator()(const Point2D &left, const Point2D &right) {
              return ((left.first < right.first) || ( (left.first == right.first) && (left.second < right.second)));
       }
};

void process();

int main() {
    process();
    return 0;
}

void process() {
    fstream target_fp;
    set<Point2D, IsSame> set_points;
    
    target_fp.open("input2.txt",ios::out);
    
    srand(time(NULL));
    
    int count = 10000; //rand()%10 + 1;
    int x = 0, y = 0;
  
    Point2D tempPoint;
   
    target_fp << count << endl;
 
    while ( set_points.size() < count) {
    x = rand()%10000;
    y = rand()%10000;
    tempPoint.first = x;
    tempPoint.second = y;
    set_points.insert(tempPoint);
    }
    set<Point2D, IsSame>::iterator it;
    for ( it = set_points.begin(); it != set_points.end(); it++ ) {
          if ( it != set_points.begin() ) {
            target_fp << endl;
          }
       target_fp << it->first << " " << it->second;
    }
        
    target_fp.close();
}


'Coding > Python 삽질기' 카테고리의 다른 글

KMP algorithm  (0) 2013.05.06
[Python] Undo / Redo 구현하기  (0) 2011.06.16
간단한 반복 작업 매크로  (0) 2011.01.12
Posted by chobocho