PAT乙级:1016. 部分A+B (C)
2016-08-13 22:08
169 查看
#include <stdio.h> #include <stdlib.h> int main() { char A[10]; char B[10]; char D_A; int count_A=0; count_A=0; int count_B=0; count_B=0; char D_B; scanf("%s %c %s %c",&A,&D_A,&B,&D_B); int i; for(i=0; i<10; i++) { if(A[i]==D_A) { count_A++; } if(B[i]==D_B) { count_B++; } } int a=(int)D_A-48;//将字符转换为整数 int b=(int)D_B-48; int Pa; int Pb; //根据是否出现了D为Pa和Pb赋初值 if(count_A==0) { Pa=0; } else { Pa=a; } if(count_B==0) { Pb=0; } else { Pb=b; } int result=0;//和 //生成Pa Pb for(i=0; i<count_A-1; i++)//因为在赋初值的时候已经给了一次 { Pa*=10; Pa+=a; } for(i=0; i<count_B-1; i++) { Pb*=10; Pb+=b; } result=Pa+Pb; printf("%d",result); system ("pause"); return 0; }
题目不难,重点在于对于没有该数出现情况的考虑。我们在实际编程之中构思好一个“公式”之后,也要思考,是不是就会有临界情况出现。祝大家编程愉快,万事如意!
相关文章推荐
- 前端的小玩意(8)——旋转的盒子(纯CSS动画效果)+可自由拖动(js)
- [AngularJS面面观] 19. 依赖注入 --- Provider是个啥
- android studio和eclipse中自定义组合控件的不同写法
- 《构建之法》读书笔记——第6章 敏捷流程
- 数据结构与算法(6)链栈
- java内存模型
- Android开源:数据库ORM框架GreenDao学习心得及使用总结
- 简单的网络爬虫实现(Jsoup使用)
- Java中引用类型和值类型的不同
- Redis深入之路(三)
- spring的几个问题
- 快速排序
- 161009_qt显示阿拉伯输入法9x7点阵
- mybatis基础知识——学习笔记(1)
- 数据库锁机制
- NFS ROOT 启动内核的配置(UBoot)
- tjut 2896
- LeetCode 108. Convert Sorted Array to Binary Search Tree
- 第二十三章 springboot + 全局异常处理
- SimpleChannelInboundHandler和ChannelInboundHandlerAdapter区别