public static void main(String[] args) { int amountOf6 = 0; // the Numbers of 6. int amountOf4 = 0; // the Numbers of 4. int amountOf2 = 0; // the Numbers of 2. int amountOf1 = 0; // the Numbers of 1. int pos = 0; /* opera*/ int splitRes = 27; //change the NO. here. int[] resultArray = new int[splitRes/6 + 2]; System.out.println("input =" + splitRes);
/* count the Numbers of 6. */ amountOf6 = splitRes/6 ; splitRes = splitRes%6; for (int i =0 ; i< amountOf6 ; i++ ){ resultArray[i] = 6; }
/* count the Numbers of 4. */ amountOf4 = splitRes/4 ; splitRes = splitRes%4; for (int i =0 ; i< amountOf4 ; i++ ){ resultArray[i +amountOf6] = 4; }
/* count the Numbers of 2. */ amountOf2 = splitRes/2 ; splitRes = splitRes%2; for (int i =0 ; i< amountOf2 ; i++ ){ resultArray[i+ amountOf6+amountOf4] = 2; }
/* count the Numbers of 1. */ if (splitRes==1){ amountOf1 = 1; resultArray[amountOf6+amountOf4+ amountOf2] = 1; } /* result output */ for(int i =0; i < resultArray.length; i++){ System.out.println("resultArray[" + i + "] = " + resultArray[i]); } } } console: input =27 resultArray[0] = 6 resultArray[1] = 6 resultArray[2] = 6 resultArray[3] = 6 resultArray[4] = 2 resultArray[5] = 1顺便问下 12C, 6C, 4C这里边 "C" 表示的是什么意思?
这是我的代码,不知道7#兄弟能不能看懂,可否帮我简化? protected String getIroInfo(double irosu) { int irosuInt = new Double(irosu).intValue(); int ret1 = irosuInt % 6; int ret2 = irosuInt / 6; String ret = ""; // 6C以上場合 if (irosu >= 6) { // 4Cの個数の判断 if (ret1 >= 4) {
变量x{x|6c,4c,2c,1c} ,变量的值是由6C到1C的降(1)如果他是大于x的,那么,可以分x,然后A = A - x;否测 x降一级,如果x = 0跳(3)。
(2)重复(1);
(3)结束;
private int[] resultArray; // split result.
private int flag;
test1(int length){
resultArray = new int[length];
}
public static void main(String[] args){
/* opera */
int splitRes = 25;
/* split */
test1 split = new test1(splitRes/6 + 2);
split.split(splitRes);
/* result output */
System.out.println("input =" + splitRes);
for(int i =0; i < split.flag; i ++){
System.out.println("resultArray[" + i + "] = " + split.resultArray[i]);
}
}
/* split */
void split(int splitRes){
if (splitRes >= 6){
splitRes -= 6;
resultArray[flag] = 6;
flag += 1;
split(splitRes);
}else if( splitRes >=4 ){
splitRes -= 4;
resultArray[flag] = 4;
flag += 1;
split(splitRes);
}else if( splitRes >=2){
splitRes -= 2;
resultArray[flag] = 2;
flag += 1;
split(splitRes);
}else if( splitRes >=1){
splitRes -= 1;
resultArray[flag] = 1;
flag += 1;
split(splitRes);
}
}
}console:
input =25
resultArray[0] = 6
resultArray[1] = 6
resultArray[2] = 6
resultArray[3] = 6
resultArray[4] = 1
public class split2 {
public static void main(String[] args) {
int amountOf6 = 0; // the Numbers of 6.
int amountOf4 = 0; // the Numbers of 4.
int amountOf2 = 0; // the Numbers of 2.
int amountOf1 = 0; // the Numbers of 1.
int pos = 0;
/* opera*/
int splitRes = 27; //change the NO. here.
int[] resultArray = new int[splitRes/6 + 2];
System.out.println("input =" + splitRes);
/* count the Numbers of 6. */
amountOf6 = splitRes/6 ;
splitRes = splitRes%6;
for (int i =0 ; i< amountOf6 ; i++ ){
resultArray[i] = 6;
}
/* count the Numbers of 4. */
amountOf4 = splitRes/4 ;
splitRes = splitRes%4;
for (int i =0 ; i< amountOf4 ; i++ ){
resultArray[i +amountOf6] = 4;
}
/* count the Numbers of 2. */
amountOf2 = splitRes/2 ;
splitRes = splitRes%2;
for (int i =0 ; i< amountOf2 ; i++ ){
resultArray[i+ amountOf6+amountOf4] = 2;
}
/* count the Numbers of 1. */
if (splitRes==1){
amountOf1 = 1;
resultArray[amountOf6+amountOf4+ amountOf2] = 1;
}
/* result output */
for(int i =0; i < resultArray.length; i++){
System.out.println("resultArray[" + i + "] = " + resultArray[i]);
}
}
}
console:
input =27
resultArray[0] = 6
resultArray[1] = 6
resultArray[2] = 6
resultArray[3] = 6
resultArray[4] = 2
resultArray[5] = 1顺便问下 12C, 6C, 4C这里边 "C" 表示的是什么意思?
int ret1 = irosuInt % 6;
int ret2 = irosuInt / 6;
String ret = ""; // 6C以上場合
if (irosu >= 6) {
// 4Cの個数の判断
if (ret1 >= 4) {
if (ret1 % 4 == 3) {
//6C,4C,2C,1C的个数
ret = ret2 + "," + (ret1 % 4) + "," + 1 + "," + 1; } else if (ret1 % 4 == 2) { ret = ret2 + "," + (ret1 % 4) + "," + 1 + "," + 0; } else { ret = ret2 + "," + (ret1 % 4) + "," + 0 + "," + 1;
}
} else if (ret1 == 3) { ret = ret2 + "," + 0 + "," + 1 + "," + 1; } else if (ret1 == 2) { ret = ret2 + "," + 0 + "," + 1 + "," + 0; } else if (ret1 == 1) { ret = ret2 + "," + 0 + "," + 0 + "," + 1; } else { ret = ret2 + "," + 0 + "," + 0 + "," + 0;
} } else { if (irosu > 4) { ret = 0 + "," + 1 + "," + 0 + "," + 1; } else if (irosu == 4) { ret = 0 + "," + 1 + "," + 0 + "," + 0;
} else if (irosu == 3) { ret = 0 + "," + 0 + "," + 1 + "," + 1; } else if (irosu == 2) { ret = 0 + "," + 0 + "," + 1 + "," + 0; } else if (irosu == 1) { ret = 0 + "," + 0 + "," + 0 + "," + 1; } else { ret = 0 + "," + 0 + "," + 0 + "," + 0;
} } return ret;
}