c语言或c++题目

杰哥特别喜欢和数字打交道,现在他有一个正整数 X,他想知道有多少个满足
要求的正整数 D 存在,要求是 D 是 X 的因子,并且 D 和 X 至少有一位相同。
★数据输入
只有一行,一个正整数 X。(N<=1000000000)。
对于 30%的数据,n<=100
对于 50%的数据,n<=200
对于 100%的数据,n<=1000000000
★数据输出
只有一行,一个整数表示满足要求的数字 D 的个数。
输入示例 输出示例
10 2

#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int main()
{    
    int X, D;
    while( cin >> X )
    {
        string num = to_string(X);
        bool tag[10] = {false};
        int  i, k;
        for(i = 0; i < num.size(); ++i)
            tag[num[i]-'0'] = true; 
        
        vector<int> factor;
        int a, b;
        i = 1;
        do{
            if( X%i == 0 ){
                a = i;
                b = X/i;
                factor.push_back(a);
                if( a != b )
                    factor.push_back(b);    
            }
            ++i;    
        }while( i*i <= X );
        
        int cnt = 0;
        for(i = 0; i < factor.size(); ++i){
            num = to_string(factor[i]);
            for(k = 0; k < num.size(); ++k)
                if( tag[num[k]-'0'] == true ){
                    cnt++;
                    break;
                }
        }
        cout << cnt << endl;        
    }
    
    return 0;
}追问

    to-string是什么意思啊   编译报错  [Error] 'to_string' was not declared in this scope

温馨提示:答案为网友推荐,仅供参考
相似回答