KeyWords:to_string();string.substr();
format output
AC CODE:
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main()
{
//freopen("sample_input.txt","r",stdin);
int M;
cin>>M;
while(M--){
int num;
cin>>num;
bool flag_found = false;
for(int j = 1; j <10 ; j ++){
int ans =j*num*num;
string str_ans = to_string(ans);
//cout<<str<<endl;
string str_to_find = to_string(num);
//std::string::size_type found = str.find(str_to_find);
string str = str_ans.substr(str_ans.size()-str_to_find.size());
//int cmp = strcmp(str1.c_str(),str2.c_str());
//cout<<str<<endl;
//cout<<str_to_find<<endl;
if(str == str_to_find){
printf("%d %d\n",j,ans);
flag_found = true;
break;
}
}
if(!flag_found)
printf("No\n");
}
return 0;
}