0
点赞
收藏
分享

微信扫一扫

java python 骑马钉


RULE = {
"2x1 4": "4 1 2 3",
"2x2 8": "1* 8* 4 5 7* 2* 6 3",
"2x2 4": "1* 4* 2 3",
"4x2 16": "1* 16* 13* 4* 8 9 12 5 3* 14* 15* 2* 6 11 10 7",
"4x2 8": "1* 8* 7* 2* 4 5 6 3",
"4x2 4": "2 3 4 1 2 3 4 1",
"4x4 32": "13* 20* 21* 12* 4 29 28 5 1* 32* 25* 8* 16 17 24 9 11* 22* 19* 14* 6 27 30 3 7* 26* 31* 2* 10 23 18 15",
"4x4 16": "5* 12* 9* 8* 4 13 16 1 3* 14* 15* 2* 6 11 10 7",
"4x4 8": "1* 8* 5* 4* 1* 8* 5* 4* 2 7 6 3 2 7 6 3",
"4x4 4": "1* 4* 1* 4* 1* 4* 1* 4* 2 3 2 3 2 3 2 3",
}


def qimading(col, row, page_count):
temp_page_count = page_count
_list = []
yushu = page_count % (row * col * 2)
if yushu:
if yushu == 4 or yushu == 8:
_list.append(yushu)
elif yushu == 12:
_list.append(4)
_list.append(8)
elif yushu == 16:
_list.append(16)
elif yushu == 24:
_list.append(8)
_list.append(16)
elif yushu == 28:
_list.append(4)
_list.append(8)
_list.append(16)
temp_page_count -= yushu

for i in range(int(temp_page_count / (col * row * 2))):
_list.append(row * col * 2)

list_result = []

start = 0
for index, item in enumerate(_list):
_len = item / 2
before_start = start + 1
before_end = start + _len
before = '%d-%d' % (before_start, before_end)

after_start = page_count - start - _len + 1
after_end = page_count - start
after = '%d-%d' % (after_start, after_end)
start += _len

key = "%dx%d %d" % (col, row, item)
rule_temp = RULE[key]

rule = ""
for _str in rule_temp.split(' '):
page = int(_str.replace('*', ''))
xx = "*" if "*" in _str else ""
rule += "%d%s " % (after_end - _len * 2 + page, xx) if page > _len else "%d%s " % (
before_start - 1 + page, xx)
rule_finlly = '%d-%dx%d %d %s %s %s' % (index, col, row, item, before, after, rule)
rule_finlly = '第%d个:%dx%d 共%d页\t前面为%s页\t后面为%s页\tQI排序规则%s' % (index + 1, col, row, item, before, after, rule)
list_result.append(rule_finlly)

for item in list_result:
print(item)


if __name__ == '__main__':
qimading(4, 4, 28)

package com.company.imposition;


import jdk.nashorn.internal.ir.annotations.Immutable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ImpositionByColRowQiMaDingUtils {
public static void main(String[] args) {
List<String> dd = qimading(4, 4, 44);
getRule(4,4,44);

}
public static Map<String,String> RULE = new HashMap<>();
static {
RULE.put("2x1 4","4 1 2 3");

RULE.put("2x2 8","1* 8* 4 5 7* 2* 6 3");
RULE.put("2x2 4","1* 4* 2 3");

RULE.put("4x2 16","1* 16* 13* 4* 8 9 12 5 3* 14* 15* 2* 6 11 10 7");
RULE.put("4x2 8","1* 8* 7* 2* 4 5 6 3");
RULE.put("4x2 4","2 3 4 1 2 3 4 1");

RULE.put("4x4 32","13* 20* 21* 12* 4 29 28 5 1* 32* 25* 8* 16 17 24 9 11* 22* 19* 14* 6 27 30 3 7* 26* 31* 2* 10 23 18 15");
RULE.put("4x4 16","5* 12* 9* 8* 4 13 16 1 3* 14* 15* 2* 6 11 10 7");
RULE.put("4x4 8","1* 8* 5* 4* 1* 8* 5* 4* 2 7 6 3 2 7 6 3");
RULE.put("4x4 4","1* 4* 1* 4* 1* 4* 1* 4* 2 3 2 3 2 3 2 3");
}
public static String getRule(int col,int row,int page_count){
List<String> qimading = qimading(col, row, page_count);
if(qimading!=null&&qimading.size()>0){
String value ="";
for(String str:qimading){
String[] arr = str.split(" |x|-");
String r = arr[arr.length-1];
r= r.replaceAll(">"," ");
value += r;
}
return value;
}
return "获取规则出错";

}
public static List<String> qimading(int col, int row, int page_count){
int temp_page_count = page_count;
List<Integer> list = new ArrayList<>();
int yushu = page_count % (col * row * 2);
if (yushu!=0){
if(yushu ==4 || yushu == 8){
list.add(yushu);
}else if(yushu == 12){
list.add(4);
list.add(8);
}else if (yushu == 16){
list.add(16);
}else if (yushu == 20){
list.add(4);
list.add(16);
}else if (yushu == 24){
list.add(8);
list.add(16);
}else if (yushu == 28){
list.add(4);
list.add(8);
list.add(16);
}
page_count -= yushu;
}

for (int i = 0; i < page_count/(col * row * 2); i++) {
list.add(col*row*2);
}
List<String> listResult = new ArrayList<>();
int start = 0;
for (int i = 0; i < list.size(); i++) {
int len = list.get(i)/2;
int beforeStart = start+1;
int beforeEnd = start+len;
String before =beforeStart+"-"+beforeEnd;
int afterStart = temp_page_count-start-len+1;
int afterEnd = temp_page_count-start;
String after = afterStart+"-"+afterEnd;
start +=len;
String key = col+"x"+row+" "+list.get(i);
String key_rule = i+"-"+col+"x"+row+" "+list.get(i)+" "+before+" "+after;
String s = RULE.get(key);
String value ="";
for(String str:s.split(" ")){
int page = Integer.valueOf(str.replaceAll("\\*",""));
String xx = str.indexOf("*")==-1?"":"*";
if(page>len){
value+= (afterEnd-len*2+page)+xx+">";
}else{
value+= (beforeStart-1+page)+xx+">";
}
}
listResult.add(key_rule+" "+value);
}
return listResult;

}

}


举报

相关推荐

0 条评论