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

int toInt(char *s){
    int sum = 0, n = strlen(s);
    for(int i = 0; i < n; i++){
        sum = sum*10 + (s[i]-'0');
    }
    return sum;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    char *s = (char*)malloc(sizeof(char)*12);
    cin>>s;
    //cout<<s<<endl;
    int n = strlen(s);
    int size = pow(2, n);
    
    int temp2, ans, res = 50;
    
    for(int i = 0; i < size; i++){
        char *temp = (char*)malloc(sizeof(char)*12); int k = 0;
        for(int j = 0; j < n; j++){
            if(i&(1<<j)){temp[k] = s[j]; k++;}
        }
        
        if(temp[0] == '0' || temp[0] == '\0'){continue;}
        ans = toInt(temp);
        //cout<<ans<<endl;
        temp2 = (int)sqrt(ans);
        if(temp2*temp2 == ans){
            if(res > (n-strlen(temp))){res = n-strlen(temp);}
        }
    }
    
    if(res == 50){cout<<-1<<endl; return 0;}
    cout<<res<<endl;
	return 0;
}

Generated URL:

Output:

2
Report Bug