c++练习266题:楼层编号

*266题

原题传送门:http://oj.tfls.net/p/266

题解:

#include<bits/stdc++.h>
using namespace std;

int t;//高能数字 
int sfch(int a){//是否有一位是高能数字,我用的递归,直到为零 
  if (a==0) 
    return 0;   else if (a%10==t)
    return 1;   else
    return sfch(a/10); } int main(){   int m,cen=0;   cin>>m>>t;   for (int i=1; i<=m; i++)//从1-m每一层判断是否是高能数字   {     if (sfch(i))     {       continue;     }//如果是,不参与计算真实楼层     cen++;   }   cout<<cen;   return 0; }

 

说明:从1遍历到编号楼层,如果有一位是高能数字就不参与计算真实楼层,最后得出真实楼层

posted @ 2022-12-07 10:20  TC2105LJY  阅读(215)  评论(0编辑  收藏  举报