水题 深搜即可 但要注意前导0的问题
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<iostream>
#define ll long long
#define ull unsigned long long
const int N=1e9+7;
const int M=1e6+5;
using namespace std;
char a[2005];
int i,n,b,c,d,e;
void dfs(int x,int y,int z)
{
b=a[x]-'0';
if(x==n-1)
{
c=sqrt(y);
if(c*c==y&&y!=0) e=max(e,z);
y=y*10+b;
c=sqrt(y);
if(c*c==y&&y!=0) e=max(e,z+1);
return ;
}
if(b!=0||y!=0) dfs(x+1,y*10+b,z+1);
dfs(x+1,y,z);
}
int main()
{
while(~scanf("%s",a))
{
e=-1;
n=strlen(a);
dfs(0,0,0);
if(e==-1) printf("-1\n");
else printf("%d\n",n-e);
}
return 0;
}