数学_高精度

数组内存放了一些个位数字,组成一个大数(从高位到低位),现在将这个数加 11,并输出加一以后的结果。

例如:

A = [2,3,1,1,4]A=[2,3,1,1,4]

则结果为 [2,3,1,1,5][2,3,1,1,5]。

A = [7,8,9]A=[7,8,9]

则结果为 [7,9,0][7,9,0]。

输入格式

第一行输入一个正整数 n(1 \leq n \leq 100)n(1≤n≤100),接下来的一行,输入用空格分隔的 nn 个 00 到 99 的非负整数组成的数组 A[n]A[n]。

输出格式

输出一行,nn 个用空格分隔的整数,表示加一后的新数组。

样例输入

5
8 9 9 9 9

样例输出

9 0 0 0 0
#include <bits/stdc++.h>
int a[105];
int main()
{
	memset(a,-1,sizeof a);
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++)
		scanf("%d",&a[i]);
	int step = n;
	bool judge = true; 
	while(judge && step>0)
	{
		a[step] = a[step]+1;
		if(a[step]!= 10)
			judge = false;
		else
		{
			a[step] = 0;
			step--;			
		}
		if(step == 0)
		{
			a[0] = 1;
			a[1] = 0;
		}
	}
	int i;
	if(a[0] == -1)
		i = 1;
	else
		i = 0;
	for(; i < n; i++)
	{
		printf("%d ",a[i]);	
	}
	if(i == n)
		printf("%d",a[i]);
	return 0;	
} /*
5
8 9 9 9 9

*/

猜你喜欢

转载自blog.csdn.net/nothing_227/article/details/81067428