为什么WA啊
查看原帖
为什么WA啊
244309
yuhaocheng楼主2021/8/2 10:45
#include <iostream>
#include <cmath>
using namespace std;

long long n;
int a[15] = {}, b[15] = {};

int main() {
    cin >> n;
    long long m = n;
    int cnt1 = 0;
    while(m) {
        a[cnt1++] = m % 10;
        m /= 10;
    }
    for(int i = sqrt(n); i >= 1; i--) {
        long long x = i * i;
        long long y = x;
        int cnt2 = 0;
        while(y) {
            b[cnt2++] = y % 10;
            y /= 10;
        }
        int pos = 0;
        for(int i = 0; i < cnt1; i++) {
            if(b[i] == a[pos]) pos++;
        }
        if(pos == cnt2) {
            cout << cnt1 - cnt2 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

2021/8/2 10:45
加载中...