#include<stdio.h> #include<iostream> #include<cstring> using namespace std; int main() { int t; int n = 1; char target[3] = { 'X','Y','Z' }; while (scanf("%d",&t)!=EOF) { getchar(); if (t == 0) { break; } cout << "Case #" << n << ":\n"; n++; for (int i = 0; i < t; i++) { int a[3] = { 0 }, b[3] = { 0 }; char p[100]; cin.getline(p,100); for (int i = 0; i<strlen(p); i=i+6) { if (p[i + 2] == 'X') { a[0] = a[0] + p[i] - '0'; b[0] = p[i + 4] - '0'; } if (p[i + 2] == 'Y') { a[1] = a[1] + p[i] - '0'; b[1] = p[i + 4] - '0'; } if (p[i + 2] == 'Z') { a[2] = a[2] + p[i] - '0'; b[2] = p[i + 4] - '0'; } } for (int i = 0; i < 3; i++) { if (b[i] == 0) { continue; } a[i] = a[i] * b[i]; b[i] = b[i] - 1; } int j = 0; int count = 0; for (int j = 0; j < 3; j++) { if (a[j] != 0) { if (count != 0) { cout << " + "; } cout << a[j]; if (b[j] != 0) { cout << " * "<< target[j] << " ^ " << b[j]; } count++; } } cout << endl; } } return 0; } |
Double click to view unformatted code.