(일반인은 다운받아도 별 소용없는거다.)
[버그있음] 때문에 새로운 버전(checker.exe)을 다운받길 권장한다.
아~주 아주 허접한 소스 공개한다.
#include <fstream.h> // for file i/o, includes iostream.h
#include <stdlib.h> // for srand() rand()
#include <time.h> // for time()
#include <conio.h> // for getch()
void main(void)
{
char max_size_c[11]="";
int max_size=1000000, my_sw=3;
char* filename="c:\\ass2_input.txt";
cout<<"--- 32bit NUMBER GENETRATOR --- by ikKo"<<endl<<endl;
cout<<"Enter number of entry (max: range of int): ";
cin.get(max_size_c, 11);
cin.ignore(1,'\n');
max_size=atoi(max_size_c);
cout<<"making "<<max_size<<" entries..."<<endl;
switch(my_sw) {
case 49:
cout<<"generating ASCENDENT number to "<<filename<<"..."<<endl;
break;
case 50:
cout<<"generating DESCENDENT number to "<<filename<<"..."<<endl;
break;
case 51:
default:
cout<<"generating RANDOM number to "<<filename<<"..."<<endl;
srand(time(NULL));
break;
}
for (int i=0;i<=max_size-1;)
{
switch(my_sw) {
case 49:
output_file<<i++<<endl;
break;
case 50:
break;
default:
case 51:
output_file<<rand()*rand()<<endl;
i++;
break;
}
if (my_sw==50) break;
}
if (my_sw==50) for (i=max_size-1;i>=0;i--) output_file<<i<<endl;
}
output_file.close();
cout<<endl<<"------------ PROCESS COMPLETED! ------------"<<endl<<endl;
}
필요하면 얼마든지 뜯어고쳐라!
저작자 copyright 이딴거 다 필요없다!ㅋ
다만 재배포만 하지 마시길!
3/27 추가포스팅: 몇몇 버그가 있어서 소스코드와 함께 다시 올린다.
변경된 사항은 코멘트가 몇가지 추가된것, 9자리 숫자가 나와야하는데 10자리가 나오는 버그, output을 check하는 프로그램이다.
// I know this is just brute force, not fully tested,
// but it's fit to purpose.
// it's free to change, modify, rebuild, compile this source code, but DO NOT REDISTRIBUTE!
// thanks for using my program, HAPPY PROGRAMMING!
// for more information, please visit: http://jihwang.org
#include <fstream.h> // for file i/o, includes iostream.h
#include <stdlib.h> // for srand() rand()
#include <time.h> // for time()
#include <conio.h> // for getch()
#include <iomanip.h> // for setw()
#define MAX_LEN 12 // used for checker(), usually need required digit+3(\n, etc)
void checker(char* IN_FILE, int line_size)
{
char a[MAX_LEN]="";
char b[MAX_LEN]="";
char output[MAX_LEN]=""; // clearing out garbages
int inta, intb, init_i=3, i=init_i;
// opening files...
ifstream input_file(IN_FILE); //open file to read
if(input_file.fail()) //input file check
cerr << "Error opening "<<IN_FILE<<endl;
else
{
input_file.getline(a, sizeof(a)); //just read first two line, it's just file header. so we can ignore this part of the file.
input_file.getline(a, sizeof(a));
input_file.getline(a, sizeof(a)); //get a line, when repeats get the next odd line
inta=atoi(a);
while (! input_file.eof()) //loop starts to get lines, stops end of the file.
{
if (line_size+init_i<=i) break;
//read file by line
input_file.getline(b, sizeof(b)); //get a line, when repeats get the next odd line
//int conversion
intb=atoi(b);
//compare
if(inta>intb) cout<<"The output is not ordered at line number "<<i<<"."<<endl;
i++;
inta=intb;
}
}
input_file.close();
}
cout<<"--- 9-digit NUMBER Generator & Checker --- by ikko"<<endl;
cout<<"for full source code please visit at http://jihwang.org"<<endl<<endl;
cout<<"Enter number of entry (max: range of int): ";
cin.get(max_size_c, 11);
cin.ignore(1,'\n');
max_size=atoi(max_size_c);
cout<<"for "<<max_size<<" entries..."<<endl;
cout<<endl<<"1. Ascendent order"<<endl<<"2. Descendent order"<<endl<<"3. Random order(default)"<<endl<<"4. Check output if it's ordered(new)"<<endl;
cout<<"choose order: "<<endl;
my_sw=getch();
cout<<endl<<endl;
switch(my_sw) {
case 49:
cout<<"generating ASCENDENT number to "<<filename<<"..."<<endl;
break;
case 50:
cout<<"generating DESCENDENT number to "<<filename<<"..."<<endl;
break;
case 52:
cout<<"checking order of "<<filename_in<<"..."<<endl;
checker(filename_in, max_size);
break;
case 51:
default:
cout<<"generating RANDOM number to "<<filename<<"..."<<endl;
srand(time(NULL));
break;
}
for (int i=0;i<=max_size-1;)
{
switch(my_sw) {
case 49:
output_file<<i++<<endl;
break;
case 50:
case 52:
break;
case 51:
default:
temporary=rand()*rand();
if (temporary>=1000000000) temporary=temporary/10;
output_file<<temporary<<endl;
i++;
break;
}
if (my_sw==50||my_sw==52) break;
}
if (my_sw==50) for (i=max_size-1;i>=0;i--) output_file<<i<<endl;
}
output_file.close();
cout<<endl<<"------------ PROCESS COMPLETED! ------------"<<endl<<endl;
}