import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;
public class Checkfile
{
public static void main(String args[]) throws IOException
{
OutputStream os = new FileOutputStream("A.in");
Random rand = new Random();
int t = rand.nextInt(100);
os.write(t);
//System.out.println(t);
while (t-- > 0)
{
int y=rand.nextInt(3000);
os.write(y);
}
}
}我得到的是不寻常的数字,而不是整数。我认为它们是十六进制的数字。我在这里试图为一个竞争性的编程问题编写一个测试用例生成器。我基本上想用Java写下面的C++代码-
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
freopen("n1.in","w",stdout);
srand(5);
int t=rand()%99+1;
assert(t<=100 && t>=1);
cout<<t<<endl;
while(t--)
{
int n=rand()%99+3;
assert(n<=100 && n>=3);
cout<<n<<endl;
}
}提前感谢!
发布于 2018-01-09 03:17:35
经过大量的搜索,我发现这里唯一的错误是我们不能将整数或除字符串之外的任何其他数据类型直接写入文件。所有其他数据类型都以二进制格式写入文件。
https://stackoverflow.com/questions/48114814
复制相似问题