intmain(){ ios::sync_with_stdio(false), cin.tie(nullptr); int N, M; while (cin >> N >> M && (N != 0 && M != 0)){ vector <int> num(N); for (int i = 0; i < N; ++i) cin >> num[i]; sort(num.begin(), num.end(), [M](constint& a, constint& b){ int ma = a % M, mb = b % M; if (ma != mb) return ma < mb; // 前小後大 -> 升序 bool a_odd = a % 2 != 0; bool b_odd = b % 2 != 0; // 假設 b_odd = false; if (a_odd != b_odd) return a_odd; // 奇數在前 if (a_odd && b_odd) return a > b; // 大奇數在前 -> 表示就要降序 return a < b; // 小偶數在前 -> 表示就要升序 }); cout << N << " " << M << '\n'; for (constint& i : num){ cout << i << '\n'; } } cout << "0 0\n"; }
voiddrawV(int rowType){ // 直線的高度是 s 所以要重複 s 次 for (int line = 0; line < s; ++line) { for (int i = 0; i < n_str.length(); ++i) { int digit = n_str[i] - '0'; int type = V_RISK[rowType][digit];
if (i > 0) cout << " ";
// 左邊的線 if (type == 1 || type == 3) cout << "|"; else cout << " ";
voiddrawH(int rowType){ for (int i = 0; i < n_str.length(); ++i){ int digit = n_str[i] - '0'; if (i > 0) cout << " "; cout << " "; for (int k = 0; k < s; ++k){ if (H_RISK[rowType][digit]) cout << "-"; else cout << " "; } cout << " "; } cout << '\n'; }
voiddrawV(int rowType){ for (int line = 0; line < s; ++line){ for (int i = 0; i < n_str.length(); ++i){ int digit = n_str[i] - '0'; int type = V_RISK[rowType][digit]; if (i > 0) cout << " "; if (type == 1 || type == 3) cout << "|"; else cout << " "; for (int k = 0; k < s; ++k) cout << " "; if (type == 2 || type == 3) cout << "|"; else cout << " "; } cout << '\n'; } }
intmain(){ ios::sync_with_stdio(false), cin.tie(nullptr); while (cin >> s >> n_str && (s != 0 || n_str != "0")){ drawH(0); drawV(0); drawH(1); drawV(1); drawH(2); cout << '\n'; } }