例如我有个txt文档d的内容如下
3
0
2
0, 0, 1
0, 1, 0
1, 0, 1
1, 1, 2
2,0,1
2,1,2
读取第一行并赋值给count
第二行赋值给ss
第三行赋值给fs
第四行起直至最后一行,设三位数分别为xyz,要将前两位数组成一个数组pair_d(x,y), 例如第四行为pair_d(0,0),z=1
第五行为pair_d(0,1),z=0 以此类推
当程序从别处读取的一个pair_w(x,y)与这里的pair_d(x,y)相同的时候,返回z
例如当程序从别处读取到pair_w(0,1)的时候,此程序需返回0
求问怎么将第四行起每一行的数字赋值才能在后面的程序实现上面的功能呢(因为有不同的文档d,虽然格式都一样但是里面的数字不一样,行数也不一样,有可能有第十一行比如3,0,2或者第十二行3,0,3,关键就是要读取每行的前两个数,并且通过比较前两个数xy返回不同第三个数z)我写到了读取第四行的方法的时候就不知道怎么将第四行赋予pair_d(x,y)并且让他们能和z有联系
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;class Automaton {
public static Automaton readAutomaton(String fileName) throws IOException{
int Count;
int ss;
int fs;
int[] automation = new int[3];
fileName = "input.txt";
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String tempString = null;
String Line1 = reader.readLine();
Count = Integer.parseInt(Line1);
String Line2 = reader.readLine();
ss = Integer.parseInt(Line2);
String Line3 = reader.readLine();
fs = Integer.parseInt(Line3); while ((tempString = reader.readLine()) != null) {
String[] tmp = tempString.split(", ");
//(从这里开始就不知道要怎么写了) } reader.close(); return null;
}
3
0
2
0, 0, 1
0, 1, 0
1, 0, 1
1, 1, 2
2,0,1
2,1,2
读取第一行并赋值给count
第二行赋值给ss
第三行赋值给fs
第四行起直至最后一行,设三位数分别为xyz,要将前两位数组成一个数组pair_d(x,y), 例如第四行为pair_d(0,0),z=1
第五行为pair_d(0,1),z=0 以此类推
当程序从别处读取的一个pair_w(x,y)与这里的pair_d(x,y)相同的时候,返回z
例如当程序从别处读取到pair_w(0,1)的时候,此程序需返回0
求问怎么将第四行起每一行的数字赋值才能在后面的程序实现上面的功能呢(因为有不同的文档d,虽然格式都一样但是里面的数字不一样,行数也不一样,有可能有第十一行比如3,0,2或者第十二行3,0,3,关键就是要读取每行的前两个数,并且通过比较前两个数xy返回不同第三个数z)我写到了读取第四行的方法的时候就不知道怎么将第四行赋予pair_d(x,y)并且让他们能和z有联系
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;class Automaton {
public static Automaton readAutomaton(String fileName) throws IOException{
int Count;
int ss;
int fs;
int[] automation = new int[3];
fileName = "input.txt";
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String tempString = null;
String Line1 = reader.readLine();
Count = Integer.parseInt(Line1);
String Line2 = reader.readLine();
ss = Integer.parseInt(Line2);
String Line3 = reader.readLine();
fs = Integer.parseInt(Line3); while ((tempString = reader.readLine()) != null) {
String[] tmp = tempString.split(", ");
//(从这里开始就不知道要怎么写了) } reader.close(); return null;
}
当程序从别处读取的一个pair_w(x,y)与这里的pair_d(x,y)相同的时候,返回z
什么意思?
什么叫从别处读取一个那什么