作为一个对编程没有很深研究的初学者,对于这些虽然没有任何算法的题仍然觉得很难很难,但是或许都是需要一个过渡时期吧,这是这几天的结果,很多有自己的考虑,自己的想法在里面,但是也百度查了很多,也看了很多别人写的关于这方面的。
先看一下关于大数方面的知识:
bool型为布尔型,占1个字节,取值0或1。
BOOL型为int型,一般认为占4个字节,取值TRUE/FALSE/ERROR。
sbyte型为有符号8位整数,占1个字节,取值范围在128~127之间。
bytet型为无符号16位整数,占2个字节,取值范围在0~255之间。
short型为有符号16位整数,占2个字节,取值范围在-32,768~32,767之间。
ushort型为无符号16位整数,占2个字节,取值范围在0~65,535之间。
int型为有符号32位整数,占4个字节,取值范围在-2,147,483,648~2,147,483,647之间。
uint型为无符号32位整数,占4个字节,取值范围在0~4,294,967,295之间。
long型为64位有符号整数,占8个字节,取值范围在9,223,372,036,854,775,808~9,223,372,036,854,775,807之间。
ulong型为64位无符号整数,占8个字节,取值范围在0~18,446,744,073,709,551,615之间。
float型为32位单精度实数,占4个字节,取值范围3.4E+10的负38次方~3.4E+10的38次方之间。
double型为64位实数,占8个字节,取值范围1.7E+10的负308次方~1.7E+10的正308次方。
这几天一直在做关于大数运算的题,就两道题我也是醉了,第一道是字符串型的,用了好久好久,提交了好多次,最后知道是哪错了吗,原来是flag这个变量没给初值,等具体的原因会在下面细说,第二道是多次大数相加,因为是我是大一新生么,对于编程很多复杂的东西还是不熟悉的,好比函数,我直到现在对它还是很模糊,现在对它真的是又爱又恨啊,因为我驾驭不了它,但是我会好好努力的。
其实关于大数加法思路其实比较简单的,但是有几点要注意的:1.要先给把存大数的数组要先归零;2.要把大数倒着存放到一个数组里面(这要避免了因为大数的长度不同而要考虑的所有问题,记得刚开始做的时候就不是这种思维);3.倒着输出即可;4.有时候要考虑0的问题。
所以让我们来看两个例题吧
1.Martian Addition
In the 22nd Century, scientists have discovered intelligent residents live on the Mars. Martians are very fond of mathematics. Every year, they would hold an Arithmetic Contest on Mars (ACM). The task of the contest is to calculate the sum of two 100-digit numbers, and the winner is the one who uses least time. This year they also invite people on Earth to join the contest.
As the only delegate of Earth, you’re sent to Mars to demonstrate the power of mankind. Fortunately you have taken your laptop computer with you which can help you do the job quickly. Now the remaining problem is only to write a short program to calculate the sum of 2 given numbers. However, before you begin to program, you remember that the Martians use a 20-based number system as they usually have 20 fingers.
Input:
You’re given several pairs of Martian numbers, each number on a line.
Martian number consists of digits from 0 to 9, and lower case letters from a to j (lower case letters starting from a to present 10, 11, …, 19).
The length of the given number is never greater than 100.
Output:
For each pair of numbers, write the sum of the 2 numbers in a single line.
Sample Input:
1234567890
abcdefghij
99999jjjjj
9999900001
Sample Output:
bdfi02467j
iiiij00000
#include<stdio.h>
#include<string.h>
int main()
{
int q[150], p[150], sum[150], i, j, len1, len2, flag, count;
char a[150], b[