一、原题
原题链接Binary Addition
mplement a function that adds two numbers together and returns their sum in binary. The conversion can be done before, or after the addition.
The binary number returned should be a string.
Examples:(Input1, Input2 --> Output (explanation)))
1, 1 --> "10" (1 + 1 = 2 in decimal or 10 in binary)
5, 9 --> "1110" (5 + 9 = 14 in decimal or 1110 in binary)
二、解题
一、分析
1、所求出是整形二进制0或1,但题中存储类型是char *,直接存入结果会变成奇异字符;采用结合ASCII解决此问题,0的ASCII为48,1为1+48,故有:(否则会有下面错误)
b=b+48;//结果与ASCII对应,与题目存储结构相同,避免显示错误
*item =(char) b;
2、int,unsigned,long,long long,存储范围不同, 题中有组测试数据超出题目所给的unsigned的存储范围,致使结果错误,故需要换存储范围更大的。
1)unsigned结果:
2)long long结果:
long long sum,a1,b1;/*int