Quiz 07
===
# [A]
## code
```c=
#include <stdio.h>
#include <math.h>
int main(){
int n;
int P, Q, R;
int found;
scanf("%d", &n);
for(int i=1; i<=n; i++){
scanf("%d %d %d", &P, &Q, &R);
found = 0;
for(int v=(int)pow(R, 1.0/3.0); v>0; v--){
for(int u=v-1; u>0; u--){
if((R - v*v*v - 2*u*u)%3 == 0){
int w = (R - v*v*v - 2*u*u)/3;
if(((5*u + 3*v + 4*w) == P) && ((u * v*v * w*w*w) == Q)){
printf("Case %d: u = %d, v = %d, w = %d\n", i, u, v, w);
found = 1;
break;
}
}
}
if(found){
break;
}
}
}
return 0;
}
```
# [B]
## code
```c=
#include <stdio.h>
int has_all_num(int, int);
int main(){
int c, n1, n2;
int found;
int has_printed = 0;
while(scanf("%d", &c) != EOF){
if(has_printed){
puts("");
}
printf("c = %d:", c);
found = 0;
for(n1=98765; n1>10000; n1--){
if(n1%c == 0){
n2 = n1 / c;
if((n2 > 999) && has_all_num(n1, n2)){
if(!found){
puts("");
found = 1;
}
if(n2 < 10000){
printf(" %d = %d * 0%d\n", n1, c, n2);
}
else{
printf(" %d = %d * %d\n", n1, c, n2);
}
}
}
}
if(!found){
printf(" No solution exists.\n");
}
has_printed = 1;
}
return 0;
}
int has_all_num(int num1, int num2){
int numbers[10] = {0};
if((num1 < 10000) || (num2 < 10000)){
numbers[0] = 1;
}
while(num1){
if(numbers[num1%10]){
return 0;
}
else{
numbers[num1%10] = 1;
num1 /= 10;
}
}
while(num2){
if(numbers[num2%10]){
return 0;
}
else{
numbers[num2%10] = 1;
num2 /= 10;
}
}
return 1;
}
```
# [C]
## code
```c=
#include <stdio.h>
int main(){
int n;
while(scanf("%d", &n) != EOF){
printf("%d = ", n);
while(n){
if(n >= 1000){
printf("M");
n -= 1000;
}
else if(n >= 900){
printf("CM");
n -= 900;
}
else if(n >= 500){
printf("D");
n -= 500;
}
else if(n >= 400){
printf("CD");
n -= 400;
}
else if((n >= 100)){
printf("C");
n -= 100;
}
else if(n >= 90){
printf("XC");
n -= 90;
}
else if(n >= 50){
printf("L");
n -= 50;
}
else if(n >= 40){
printf("XL");
n -= 40;
}
else if(n >= 10){
printf("X");
n -= 10;
}
else if(n >= 9){
printf("IX");
n -= 9;
}
else if(n >= 5){
printf("V");
n -= 5;
}
else if(n >= 4){
printf("IV");
n -= 4;
}
else{
printf("I");
n -= 1;
}
}
puts("");
}
return 0;
}
```
###### tags: `程設一quiz`