浙工大15新生赛 江老板A+B

来源:互联网 发布:对接淘宝库存管理软件 编辑:程序博客网 时间:2024/06/05 17:57
#include <iostream>#include <stack>#include <algorithm>using namespace std;const int prime[] = { 0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };int main() {int Lu[53], Hui[53], Yi[53], Zheng[53];Lu[0] = Hui[0] = 0;char c;int len1, len2;Lu[1] = Hui[1] = 1;stack<int> q;while (Lu[1] && Hui[1]) {int i = 1;memset(Yi, 0, sizeof(Yi));memset(Zheng, 0, sizeof(Zheng));for (;;) {scanf("%d%c", &Lu[i], &c);i++;if (c == ' ') {len1 = i - 1;break;}}i = 1;for (;;) {scanf("%d%c", &Hui[i], &c);i++;if (c == '\n') {len2 = i - 1;break;}}if (len1 >= len2) {for (int i = len1 - len2 + 1, j = 1; j <= len2; i++, j++) {Yi[i] = Hui[j];}for (int i = 1; i <= len1; i++)Zheng[i] = Lu[i];}if (len2 >= len1) {for (int i = len2 - len1 + 1, j = 1; j <= len1; i++, j++) {Yi[i] = Lu[j];}for (int i = 1; i <= len2; i++)Zheng[i] = Hui[i];}int e = max(len1, len2);for (int i = e, k = 1; i >= 0; i--, k++) {if (Zheng[i] + Yi[i] < prime[k]) {q.push(Zheng[i] + Yi[i]);}else if (Zheng[i] + Yi[i] >= prime[k]) {q.push((Zheng[i] + Yi[i]) % prime[k]);Yi[i - 1]++;}}cout << q.top();q.pop();while (!q.empty()) {int w = q.top();q.pop();printf(",%d", w);}cout << endl;}return 0;}

0 0
原创粉丝点击