【CodeForces】[75A]Life Without Zeros
来源:互联网 发布:ps3无限验证游戏数据 编辑:程序博客网 时间:2024/06/07 05:16
题意:
正常运算的话101+102=203
当去除式子中所有的0时变为
11+12=23
发现等式仍然成立
而105+106=211去除所有0变为
15+16=211很显然不成立
所以给出两个数字
判断它们相加的式子去除所有0后是否成立
解题过程:
因为题目表示去除所有的0
那么可以通过
Int tc=0; while(c) { if(c%10) tc*=10; tc+=c%10; c/=10; }c=0; while(tc) { c=c*10+tc%10; tc/=10; }
来去除数字c中的0
最后判断去除0后的两个数相加
是否等于相加后去除0即可
另外需要注意数据范围
int有可能会溢出
#include<stdio.h>int main() { __int64 a,b; while(scanf("%I64d",&a)!=EOF) { scanf("%I64d",&b); __int64 c=a+b; __int64 tc=0; while(c) { if(c%10) tc*=10; tc+=c%10; c/=10; } c=0; while(tc) { c=c*10+tc%10; tc/=10; } __int64 ta=0; while(a) { if(a%10) ta*=10; ta+=a%10; a/=10; } a=0; while(ta) { a=a*10+ta%10; ta/=10; } __int64 tb=0; while(b) { if(b%10) tb*=10; tb+=b%10; b/=10; } b=0; while(tb) { b=b*10+tb%10; tb/=10; } printf("%s\n",c==a+b?"YES":"NO"); } return 0;}
题目地址:【CodeForces】[75A]Life Without Zeros
0 0
- CodeForces 75A .Life Without Zeros
- 【CodeForces】[75A]Life Without Zeros
- codeforces-75A Life Without zeros
- Codeforces 75A:Life Without Zeros(水题)
- A. Life Without Zeros
- A. Life Without Zeros
- 【CodeForces】67A - Life Without Zeros(水)
- 【水模拟】#67 A. Life Without Zeros
- Life Without Zeros
- 【codeforces】-- Life Without Zeros(两个数先加后消去包含的零和先消后加判断是否相等 )
- CodeForces 556A Case of the Zeros and Ones
- CodeForces-556A Case of the Zeros and Ones
- codeforces 556A Case of the Zeros and Ones
- Codeforces 556A:Case of the Zeros and Ones
- CodeForces 556A Case of the Zeros and Ones
- 【52.49%】【codeforces 556A】Case of the Zeros and Ones
- 265. Life without a friend is death. 没有朋友,虽生犹死
- Life Without Internet
- LODOP
- 69道Spring面试题和答案
- iOS UIAlertController使用方法如何使用
- 有趣的学习方式
- HDOJ/HDU 2567 寻梦(字符串简单处理)
- 【CodeForces】[75A]Life Without Zeros
- bash功能 快捷键
- Dart入门—函数与运算符
- Fully Qualified URL【完全限定URL】
- 【bzoj 1002】[FJOI2007]轮状病毒(乱搞+结论)
- 安卓菜鸟开发笔记(10-8)多媒体播放器api
- 数据结构——图
- ZigBee IAR编译问题 Fatal Error[e72]: Segment BANKED_CODE must be defined in a segment definition option
- eclipse错误: 找不到或无法加载主类解决过程