1785: 又一道简单题

Submit Page   Summary   Time Limit: 5 Sec     Memory Limit: 128 Mb     Submitted: 602     Solved: 234


Description

输入一个四个数字组成的整数 n,你的任务是数一数有多少种方法,恰好修改一个数字,把它 变成一个完全平方数(不能把首位修改成 0)。比如 n=7844,有两种方法:3844=62^2和 7744=88^2。

Input

输入第一行为整数 T (1<=T<=1000),即测试数据的组数,以后每行包含一个整数 n (1000<=n<=9999)。

Output

对于每组数据,输出恰好修改一个数字,把 n 变成完全平方数的方案数。

Sample Input

2
7844
9121

Sample Output

Case 1: 2
Case 2: 0

Hint

Source

湖南省第十一届大学生计算机程序设计竞赛

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#include<map>
#include<sstream>
#include<queue>
#include<cmath>
#include<list>
#include<vector>
#include<string>
using namespace std;
#define long long ll
const double PI = acos(-1.0);
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int N = ;
int n, m, tot;
int a[];
int r[], c[];
int x, y, pr, pc, k = ;
int ok(int x)
{
int tp=sqrt(x*1.0);
return tp*tp==x;
}
int change(string s)
{
int sum = ;
for(int i=; i<s.size(); i++)
{
sum = sum * + s[i] - '';
}
return sum;
}
int sq[];
void init()
{
int k = ;
for(int i=; i<; i++)
sq[k++] = i * i;
}
int main()
{ int t, k = ;
cin >> t;
while(t--)
{
string s, s1, s2, s3, s4;
int cnt = ;
cin>>s;
int a,b,c,d;
s1 = s;s2 = s;s3 = s;s4 = s; //将s分别复制给中间变量
a = s1[]-''; b = s2[]-''; c = s3[]-''; d = s4[]-''; //记录原4位数各个数位数值
//printf("%d %d %d %d\n",a,b,c,d);
for(int i=; i<= ; i++) //第一位改变不能和原来的相等&&第一位不能为0
{
if(i==a) continue; //注意!不能把i!=a写在for循环里面 一遇到a会直接跳出循环而漏掉情况!!!
s1[] = i + ''; //改变第一位
//cout<<s1[0]<<endl;
if(ok(change(s1))) { //将字符串变为数值再判断是否为完全平方数
//printf("%d\n",change(s1));
cnt++;
}
}
for(int i=; i<= ; i++)
{
if(i==b) continue;
s2[] = i + '';
//cout<<s2[1] <<endl;
if(ok(change(s2))){
//printf("%d\n",change(s2));
cnt++;
}
}
for(int i=; i<= ; i++)
{
if(i==c) continue;
s3[] = i + '';
//cout<<s3[2]<<endl;
if(ok(change(s3))) {
//printf("%d\n",change(s3));
cnt++;
}
}
for(int i=; i<= ; i++)
{
if(i==d) continue;
s4[] = i + '';
//cout<<s4[3]<<endl;
if(ok(change(s4))) {
//printf("%d\n",change(s4));
cnt++;
}
}
printf("Case %d: ",k++);
cout<<cnt<<endl;
}
return ;
}

最新文章

  1. JavaScript 全栈工程师培训教程(来自阮一峰)
  2. ShareSdk使用心得
  3. css中visiblity和display异同
  4. centos7重启rsyslog服务|centos7重启syslog服务
  5. malloc、calloc、realloc的区别
  6. sql server 2016 management studio没有的解决方式
  7. 基于Tengine的反向代理详细配置
  8. 一个简单的Inno Setup例子
  9. linux shell 中&quot;2&gt;&amp;1&quot;含义
  10. Linux:备份
  11. jQuery原型技术分解
  12. 常用的十大Python开发工具
  13. commons-lang3 事件机制 &lt;EventListenerSupport&gt;
  14. openstack-mitaka部署
  15. odoo qweb 记录
  16. SwipeableFlatList 实现类似于QQ列表滑动
  17. 利用mycat实现基于mysql5.5主从复制的读写分离
  18. MyCAT简易入门 (Linux)
  19. centos 安装elk监控
  20. Docker容器学习与分享10

热门文章

  1. B1056 组合数的和 (15分)
  2. HDU 6153 KMP
  3. appcompat_v7\res\values-v21\themes_base.xml:158: error: Error: No resource
  4. json对象数据列数
  5. 极简Node教程-七天从小白变大神(二:中间件是核心)
  6. 【Restore IP Addresses 】cpp
  7. easyui在datagrid只想选择一条
  8. 在控制器“xxxx”上找不到与该请求匹配的操作
  9. httpClient get方式抓取数据
  10. 一个 Observation