PAT 1121 祖传好运 15分

92 阅读1分钟

1121 祖传好运 - PAT (Basic Level) Practice (中文) (pintia.cn)

#include<bits/stdc++.h>
using namespace std;
int flag;
int cnt;
int main()
{
    int n; cin >> n;

    for (int i = 0; i < n; i++)
    {
        cnt = 0;
        string temp; cin >> temp;
        int len = temp.size();
        for (int i = 1; i <= len; i++)
        {
            flag = 0;
            string t = temp.substr(0, i);
            //cout<<t<<endl;
            int intt = stoi(t);

            if (intt % i == 0)
            {
                flag = 1;
                cnt++;
            }
        }

        if (cnt == len)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}