java语言实现满足多条件匹配简单过滤输出问题
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/18 21:03:59
java语言实现满足多条件匹配简单过滤输出问题
用java语言同时满足下列2个条件就输出源代码
(1)假定从1-11这11个数字中任选6个全组合输出(每行输出6个不相同数字,并且从小到大排列)
(2)将第一问得到数据过滤,并且同时满足下面3条条件就输出,输出结果用"116.txt"保存在C盘
01,02,03含有1至2个
02,06,08,09含有1至3个
01,06,07,08,09,10,11含有0至2个
正确输出结果如下
02,03,04,05,10,11
02,03,04,05,09,11
02,03,04,05,09,10
02,03,04,05,08,11
02,03,04,05,08,10
02,03,04,05,08,09
02,03,04,05,07,11
02,03,04,05,07,10
02,03,04,05,07,09
02,03,04,05,07,08
02,03,04,05,06,11
02,03,04,05,06,10
02,03,04,05,06,09
02,03,04,05,06,08
02,03,04,05,06,07
用java语言同时满足下列2个条件就输出源代码
(1)假定从1-11这11个数字中任选6个全组合输出(每行输出6个不相同数字,并且从小到大排列)
(2)将第一问得到数据过滤,并且同时满足下面3条条件就输出,输出结果用"116.txt"保存在C盘
01,02,03含有1至2个
02,06,08,09含有1至3个
01,06,07,08,09,10,11含有0至2个
正确输出结果如下
02,03,04,05,10,11
02,03,04,05,09,11
02,03,04,05,09,10
02,03,04,05,08,11
02,03,04,05,08,10
02,03,04,05,08,09
02,03,04,05,07,11
02,03,04,05,07,10
02,03,04,05,07,09
02,03,04,05,07,08
02,03,04,05,06,11
02,03,04,05,06,10
02,03,04,05,06,09
02,03,04,05,06,08
02,03,04,05,06,07
package zhidao;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
public class Combin
{
private static String line = System.getProperty ("line.separator");
private static LinkedList<String[]> recursionSub ( LinkedList<String[]> list, int count, String[] array, int ind,
int start, int... indexs )
{
start++;
if (start > count - 1)
{
return null;
}
if (start == 0)
{
indexs = new int[array.length];
}
for ( indexs[start] = ind; indexs[start] < array.length; indexs[start]++ )
{
recursionSub (list, count, array, indexs[start] + 1, start, indexs);
if (start == count - 1)
{
String[] temp = new String[count];
for ( int i = count - 1; i >= 0; i-- )
{
temp[start - i] = array[indexs[start - i]];
}
boolean flag = true;
L: for ( int i = 0; i < temp.length; i++ )
{
for ( int j = i + 1; j < temp.length; j++ )
{
if (temp[i] == temp[j])
{
flag = false;
break L;
}
}
}
if (flag)
{
list.add (temp);
}
}
}
return list;
}
private static void filter ( LinkedList<String[]> list ) throws IOException
{
File file = new File ("c:/116.txt");
FileWriter fw = new FileWriter (file);
for ( String[] strings : list )
{
int count1 = 0, count2 = 0, count3 = 0;
String temp = Arrays.toString (strings).replaceAll ("[\\[\\]\\s]", "");
if (temp.contains ("01"))
{
count1++;
count3++;
}
if (temp.contains ("02"))
{
count1++;
count2++;
}
if (temp.contains ("03"))
{
count1++;
}
if (temp.contains ("06"))
{
count2++;
count3++;
}
if (temp.contains ("08"))
{
count2++;
count3++;
}
if (temp.contains ("09"))
{
count2++;
count3++;
}
if (temp.contains ("07"))
{
count3++;
}
if (temp.contains ("10"))
{
count3++;
}
if (temp.contains ("11"))
{
count3++;
}
if (count1 >= 1 && count1 <= 2 && count2 >= 1 && count2 <= 3 && count3 >= 0 && count3 <= 2)
{
fw.write (temp + line);
}
}
fw.flush ();
fw.close ();
}
public static void main ( String[] args ) throws IOException
{
String[] A = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11" };
LinkedList<String[]> list = new LinkedList<String[]> ();
recursionSub (list, 6, A, 0, -1);
// 假定从1-11这11个数字中任选6个全组合输出(每行输出6个不相同数字,并且从小到大排列)
for ( String[] strings : list )
{
String temp = Arrays.toString (strings).replaceAll ("[\\[\\]\\s]", "");
System.out.println (temp);
}
// 将第一问得到数据过滤,并且同时满足下面3条条件就输出,输出结果用"116.txt"保存在C盘
filter (list);
}
}
再问: 那个1-129行用什么输入的
再答: 什么?这是百度自己的富文本编辑器啊,你很感兴趣么?
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
public class Combin
{
private static String line = System.getProperty ("line.separator");
private static LinkedList<String[]> recursionSub ( LinkedList<String[]> list, int count, String[] array, int ind,
int start, int... indexs )
{
start++;
if (start > count - 1)
{
return null;
}
if (start == 0)
{
indexs = new int[array.length];
}
for ( indexs[start] = ind; indexs[start] < array.length; indexs[start]++ )
{
recursionSub (list, count, array, indexs[start] + 1, start, indexs);
if (start == count - 1)
{
String[] temp = new String[count];
for ( int i = count - 1; i >= 0; i-- )
{
temp[start - i] = array[indexs[start - i]];
}
boolean flag = true;
L: for ( int i = 0; i < temp.length; i++ )
{
for ( int j = i + 1; j < temp.length; j++ )
{
if (temp[i] == temp[j])
{
flag = false;
break L;
}
}
}
if (flag)
{
list.add (temp);
}
}
}
return list;
}
private static void filter ( LinkedList<String[]> list ) throws IOException
{
File file = new File ("c:/116.txt");
FileWriter fw = new FileWriter (file);
for ( String[] strings : list )
{
int count1 = 0, count2 = 0, count3 = 0;
String temp = Arrays.toString (strings).replaceAll ("[\\[\\]\\s]", "");
if (temp.contains ("01"))
{
count1++;
count3++;
}
if (temp.contains ("02"))
{
count1++;
count2++;
}
if (temp.contains ("03"))
{
count1++;
}
if (temp.contains ("06"))
{
count2++;
count3++;
}
if (temp.contains ("08"))
{
count2++;
count3++;
}
if (temp.contains ("09"))
{
count2++;
count3++;
}
if (temp.contains ("07"))
{
count3++;
}
if (temp.contains ("10"))
{
count3++;
}
if (temp.contains ("11"))
{
count3++;
}
if (count1 >= 1 && count1 <= 2 && count2 >= 1 && count2 <= 3 && count3 >= 0 && count3 <= 2)
{
fw.write (temp + line);
}
}
fw.flush ();
fw.close ();
}
public static void main ( String[] args ) throws IOException
{
String[] A = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11" };
LinkedList<String[]> list = new LinkedList<String[]> ();
recursionSub (list, 6, A, 0, -1);
// 假定从1-11这11个数字中任选6个全组合输出(每行输出6个不相同数字,并且从小到大排列)
for ( String[] strings : list )
{
String temp = Arrays.toString (strings).replaceAll ("[\\[\\]\\s]", "");
System.out.println (temp);
}
// 将第一问得到数据过滤,并且同时满足下面3条条件就输出,输出结果用"116.txt"保存在C盘
filter (list);
}
}
再问: 那个1-129行用什么输入的
再答: 什么?这是百度自己的富文本编辑器啊,你很感兴趣么?
Java匹配正则表达式的实现
c语言简单图像输出问题
运用JAVA语言实现对一句话的移位,例如:输入“I like dancing”输出“like dancing I dan
一个很简单的C语言问题,我就是想实现:输入一系列数字,然后以0为标志结束输入,再输出之前输入的数字
JAVA split("|") 简单的问题~
c语言 查找并输出满足给定条件的一组整数
excel中怎样用函数实现不同两个表格间的满足多条件返回值的问题
从键盘输入一个自然数,如果是质数,则直接输出,如果是合数,则分为两个质数的和.用java语言实现.急!
java语言实现求1+2+3……+1000的和,把和输出,计算每步结果中有多少个最后以8结尾的.
java语言编程 猴子吃桃问题
java语言的一个小问题
Java.do-while循环问题.使用do-while循环结构实现:计算1至50中是7点倍数的数值之和并输出.