| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
写了个数据生成器In Reply To:我全部用字符串处理,怎么还是WA? Posted by:debug1984 at 2005-01-18 23:25:36
这个主要用来测试你的时间限制的。假设n是100,000
生成后的数据保存在mydata.txt里面。
C++代码如下:
//data generator
#include <iostream>
#include <fstream>
using namespace std;
int
main()
{
ofstream out("mydata.txt");
int n;
int i,j;
int bitcnt;
int marki,markj;
char gen[17];
for(n=0;n<100000;n++)
{ bitcnt=0;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
if(bitcnt==7) break;
gen[i*4+j]=rand()%('Z'+1);
bitcnt++;
if(gen[i*4+j]<'0')
{
gen[i*4+j]='-';
bitcnt--;
if(i!=0||(i==0&&j!=0))
{if(gen[i*4+j-1]=='-')
{gen[i*4+j]='9'+1;
bitcnt++;
}
}
}
if(gen[i*4+j]>'9'&&gen[i*4+j]<'A')
gen[i*4+j]='A'+rand()%26;
if(gen[i*4+j]=='Q') gen[i*4+j]--;
if(gen[i*4+j]=='Z') gen[i*4+j]--;
if(i==3&&j==3&&bitcnt<7) {i=0;j=0;bitcnt=0;}
marki=i;
markj=j;
}
gen[marki*4+markj+1]='\0';
out<<gen<<endl;
}
out.close;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator