- 分享
- 0
- 人气
- 0
- 主题
- 5
- 帖子
- 1042
- UID
- 105681
- 积分
- 3194
- 阅读权限
- 21
- 注册时间
- 2007-10-19
- 最后登录
- 2012-8-4
- 在线时间
- 753 小时
|
弄到了~~
- int[] a = { 0, 3, 100, 2, 2, 3, 0, 4 }; //2x100+3x2+4
- int[] b = { 0, 3, 98, 6, 2, 4, 1, 1 }; //6x98+4x2+x
- int[] c = new int[22];
- int p = 2, q = 2, r = 2;
- while (p <= a[1] * 2 && q <= b[1] * 2)
- {
- if (a[p] == b[q])
- {
- c[r] = a[p]; c[r + 1] = a[p + 1] + b[q + 1];
- p += 2; q += 2; r += 2;
- }
- else if (a[p] > b[q])
- {
- c[r] = a[p]; c[r + 1] = a[p + 1];
- r += 2;
- c[r] = b[q]; c[r + 1] = b[q + 1];
- r += 2; p += 2; q += 2;
- }
- else
- {
- c[r] = b[q]; c[r + 1] = b[q + 1];
- r += 2;
- c[r] = a[p]; c[r + 1] = a[p + 1];
- r += 2; p += 2; q += 2;
- }
- }
- c[1] = (r - 1) / 2;
- for (int i = 2; i < p; i += 2)
- {
- if (a[i] != 0 && a[i] != 1 && a[i + 1] != 1)
- Console.Write(a[i + 1] + "x" + a[i]);
- if (a[i] == 1 && a[i + 1] == 1)
- Console.Write("x");
- if (a[i] == 0)
- Console.Write(a[i + 1]);
- if (i == p - 2)
- Console.Write("");
- else
- Console.Write(" + ");
- }
- Console.WriteLine();
- for (int j = 2; j < q; j += 2)
- {
- if (b[j] != 0&&b[j] != 1 && b[j + 1] != 1)
- Console.Write(b[j + 1] + "x" + b[j]);
- if (b[j] == 1 && b[j + 1] == 1)
- Console.Write("x");
- if (b[j] == 0)
- Console.Write(b[j + 1]);
- if (j == q - 2)
- Console.Write("");
- else
- Console.Write(" + ");
- }
- Console.WriteLine();
- for (int h = 1; h <= 30; h++)
- Console.Write("-");
- Console.WriteLine();
- for (int k = 2; k < r; k += 2)
- {
- if (c[k] != 0 && c[k] != 1 && c[k + 1] != 1)
- Console.Write(c[k + 1] + "x" + c[k]);
- if(c[k]==0)
- Console.Write(c[k + 1]);
- if (c[k] == 1 && c[k + 1] == 1)
- Console.Write("x");
- if (k == r - 2)
- Console.Write("");
- else
- Console.Write(" + ");
- }
- Console.WriteLine();
- }
复制代码 |
|