我的方法跑不出来,求大神解答!感恩
查看原帖
我的方法跑不出来,求大神解答!感恩
1349396
Fwdx_Su楼主2024/5/3 17:49

按照这样的方法去求解,跑不出来,一直显示TLE,求大神解答哪里有问题?

#include<iostream>
using namespace std ;
int main()
{
    int n,x =0 ;
    int fig = 1;//1-n的数字
    int bit = 0;//割下来的个位数字
    int time = 0 ;//出现次数
    cin >> n ;
    cin >> x ;
    for(int i = 0 ; i < n ; i++)
    {
        int temfig = 0 ;
        temfig=fig ;//把数字fig存入临时temfig,防止fig被改变
        while(temfig>9)
        {
            bit = temfig % 10 ;
            if (bit == x)
            {
                time++ ;
            }
            temfig = temfig/10 ;
        }
        while(temfig<10)
        {
            bit = temfig ;
            if(bit == x )
            {
                time ++ ;
            }
        }
        fig++ ;

    }
    cout << time ;
    return 0 ;
}
2024/5/3 17:49
加载中...