C/C++の宿題を片付けます 104代目
■ このスレッドは過去ログ倉庫に格納されています
0366デフォルトの名無しさん
2008/02/22(金) 05:53:24とりあえず適当
(1)
#include<stdio.h>
void num2roma(int num,const char roma[]){
const int mod = num % 10;
const int div = num / 10;
const int mod5 = num % 5;
int i;
if(div)num2roma(div,roma+2);
if(mod5==4){
putchar(roma[0]);
putchar(roma[mod/4]);
}else{
if(mod5!=mod)
putchar(roma[1]);
for(i=0;i<mod5;++i)
putchar(roma[0]);
}
}
int main(void){
int num;
while(scanf("%d",&num)==1){
num2roma(num,"IVXLCDM");
putchar('\n');
}
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています