输入文件:in.in(从in.in文件中读取两个整数,第一个整数是对应的十进制数,第二个整数是进制数。)
输出文件:out.out(将结果输出到out.out文件中,输出一行,从前到后依次是转换后各个数位上的数字,用空格分开,不能输出多余空格。)
输入样例:13 2
输出样例:1 1 0 1
尝试代码如下:
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
FILE *fp,*tp; int a,b,c;
if ( fp=fopen("in.in","r") ) {
if ( tp=fopen("out.out","w+") ) {
while ( !feof(fp) ) {
if ( fscanf(fp,"%d",&a)==1 ) {
c=1;
b=0;
while(a){
b+=a%10*c; a/=10; c*=2;
}
fprintf(tp,"%d ",b);
}
}
fclose(tp);
} printf("Can't Out out.out'\n");
fclose(fp);
}
else printf("Can't Open in.in'\n");
return 0;
}
请各位帮忙,我的最终答案是5 2不过不对