Skip to content

Instantly share code, notes, and snippets.

@LYP951018
Last active December 29, 2015 05:39
Show Gist options
  • Select an option

  • Save LYP951018/7623414 to your computer and use it in GitHub Desktop.

Select an option

Save LYP951018/7623414 to your computer and use it in GitHub Desktop.
for ACM
#include<stdio.h>
#define MAX 100000
int main()
{
int _c[MAX];
int b[MAX];
int c[MAX];//定义数组来存储数
int q=0;//用于循环进行计算
int x=0;//用于将数组中的每一位赋给另一个数组
int start=0;//用于记录输出结果的起始项
int i=0;//用于初始化数组的计数
int count;
scanf("%d",&count);//接收用户数据,决定计算次数
for(i=0;i<MAX;i++)
{
_c[i]=0;
c[i]=0;
b[i]=0;
}//给数组中每个元素的值初始化为0
b[MAX-1]=1;
for(q=0;q<count-1;q++)//循环
{
for(x=MAX-1;x>-1;x--)
{
_c[x]=c[x];
}//通过_c来保存上一次循环中c的值
for(x=MAX-1;x>-1;x--)
{
c[x]=b[x];
}
for(x=MAX-1;x>-1;x--)
{
b[x]=b[x]+_c[x];//通过求前两项之和来求数列
if(b[x]>=10)//模仿人对于加法的运算,判断加和后结果是否大于十,如果大于十则将这位减十,并进一位
{
b[x]=b[x]-10;
b[x-1]++;//逢十进一
}
}
}
//printf("b=%d\nc=%d\n",b[98],c[98]);
for(q=MAX-1;q>-1;q--)
{
b[q]=b[q]+c[q];
if(b[q]>=10)//模仿人对于加法的运算,判断加和后结果是否大于十,如果大于十则将这位减十,并进一位
{
b[q]=b[q]-10;
b[q-1]++;//逢十进一
}
}
while(b[start]==0)
{
start++;
}
for(start=start;start<MAX;start++)
{
printf("%d",b[start]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment