Noip编程真题
/*
1 ...11,包括4个1。
按任意键继续
*/
//?算进去吗?:?11?1
#包含?& ltstdio.h & gt
int?IncludeX(int?n,?int?x)?{
int?我,我,sum?=?0;
对于(我?=?1;?我?& lt=?n;?++i)?{
m?=?我;
while(m)?{
如果(m?%?10?==?x)?++ sum;?//?检查是否有X,有X就重写计数器。
m?/=?10;?//?下一轮检查高一级。
}
}
回归?总和;
}
int?main()?{
int?n,x,sum
文件?*inFile,?* outFile
inFile?=?fopen("count.in "," rt ");
outFile?=?fopen("count.out "," wt ");
如果(inFile?==?NULL?||?outFile?==?NULL)?{
Printf("无法打开文件。\ n ");
回归?1;
}
fscanf(inFile," %d%d ",& ampn & amp;x);
fclose(inFile);
sum?=?IncludeX(n,x);
printf("1?...?%d包含%d \ n”,n,sum,x);
fprintf(outFile," %d\n ",sum);
fclose(outFile);
回归?0;
}