A+B IV
来源:互联网 发布:微商裂变软件 编辑:程序博客网 时间:2024/06/07 08:56
A+B IV
Time Limit : 1000 MS Memory Limit : 65536 KBDescription
题目描述
小明喜欢做a+b的算术,但是他经常忘记把末位对齐,再进行加,所以,经常会算错。比如12+13,他把12左移了1位,结果变成了133。小明已经算了一些等式,请计算一下他到底移动了多少位。
输入
第一行是一个整数K,表示样例的个数。以后每行一个样例,形如a+b=c, 1≤a,b≤1e4;0≤c≤1e9。
输出
每行输出一个样例的结果,以b为标准,a如果往左移n位,输出n,如果往右移n位,输出-n。测试数据保证一定有解,如果存在多个解,输出左移的结果。
样例输入
612+13=121312+13=131212+13=2512+13=1201312+13=13312+13=142
样例输出
2-2031-1
Sample Input
Sample Output
题意:给出一个算式,判断该算式的结果是由两个加数如何移位得到思路:直接使用循环来判断求得结果。写题时候感觉两个注意点,一个是正数中不存在转负数时的判断,即题中if(t)。其次就是对于循环中n的取值,开始我是用的pow(10,n),n的范围取得1到9,结果提交上去WA了,我觉得应该是n取9时10^9太大了,计算过程中超时了。ps:这些只是个人观点,因为个人水平原因所以不一定正确,欢迎各位路过的大佬在评论区留言指正~~~
#include <stdio.h>#include <math.h>int main(){ int k; scanf("%d",&k); while(k--){ int a,b,c,n,s=0,t=1; scanf("%d+%d=%d",&a,&b,&c); if(a+b==c){ printf("0\n"); }else{ for(n=10;n<=1000000000;n*=10){ s++; if(a*n+b==c){ t=0; printf("%d\n",s); }else continue; } if(t){ s=0; for(n=10;n<1000000000;n*=10){ s--; if(a+b*n==c){ printf("%d\n",s); }else continue; } } } }}
阅读全文
0 0
- A+B Problem IV
- A+B Problem IV
- A+B Problem IV
- A+B Problem IV
- A+B Problem IV
- A+B IV
- A+B Problem IV
- A+B Problem IV
- XTU1214 A+B IV
- NYOJ513-A+B Problem IV
- 【A+B Problem IV 513 】
- acm-A+B Problem IV
- NYOJ513 A+B Problem IV
- NYOJ513,A+B Problem IV
- nyoj513 A+B Problem IV
- A+B for Input-Output Practice (IV)
- NYOJ 513 A+B Problem IV
- A+B for Input-Output Practice (IV)
- 数据库质疑或只有MDF文件资料
- 玲珑杯河南专场E
- css常见的水平垂直居中
- VS下建立自己的caffe工程项目
- 监控系统故障定位之事件关联分析的设计
- A+B IV
- delphi的取整函数round、trunc、ceil和floor
- Centons7上安装Ansible
- Kubernetes 1.6 出现RBAC问题解决方法。
- 快乐数
- iOS中引用第三方类库的方法总结
- Delphi第三方控件安装卸载指南
- Controller中private方法注入的Service为null
- CommandBehavior.CloseConnection