1
#include<stdio.h>
2
#include<string.h>
3
char *add(char s1[],char s2[])
4![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
5
char str1[1100],str2[1100],str3[1100];
6
int t1,t2,i,save=0,j;
7
strcpy(str1,strlen(s1)>=strlen(s2)?s1:s2);
8
strcpy(str2,strlen(s1)<strlen(s2)?s1:s2);
9
t1=strlen(str1);
10
t2=strlen(str2);
11
for(i=1;i<=t2;i++)
12
str1[t1-i]+=(str2[t2-i]-'0');
13
for(i=t1-1;i>=0;i--)
14
if(str1[i]>'9')
15![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
16
str1[i]=(str1[i]-'0')%10+'0';
17
if(i!=0) str1[i-1]++;
18
else save=1;
19
}
20
t1=strlen(str1);j=0;
21
if(save!=1)
22
return str1;
23
if(save==1)
24![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
25
j=1;
26
for(i=0;i<t1;i++)
27![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{str3[j]=str1[i];j++;}
28
str3[0]='1';
29
str3[j]='\0';
30
return str3;
31
}
32
}
33
int main()
34![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
35
char a[800],b[800];
36
int la,lb,i,j,k,l,pa,pb,l2,p,lb1,lb2;
37
char az[800],ax[800],bz[800],bx[800],anz[800],anx[800];
38
while(scanf("%s%s",a,b)!=EOF)
39![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
40
memset(az,0,sizeof(az));
41
memset(anz,0,sizeof(anz));
42
memset(anx,0,sizeof(anx));
43
memset(ax,0,sizeof(ax));
44
memset(bz,0,sizeof(bz));
45
memset(bx,0,sizeof(bx));
46
la=strlen(a);
47
pa=pb=0;
48
lb=strlen(b);
49
j=k=0;
50
for(i=0;i<la;i++)
51![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
52
if(a[i]=='.')
53![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
54
pa=1;
55
continue;
56
}
57
if(pa==0)
58![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
59
az[j]=a[i];
60
j++;
61
}
62
if(pa)
63![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
64
ax[k]=a[i];
65
k++;
66
}
67
}
68
j=k=0;
69
for(i=0;i<lb;i++)
70![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
71
if(b[i]=='.')
72![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
73
pb=1;
74
continue;
75
}
76
if(pb==0)
77![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
78
bz[j]=b[i];
79
j++;
80
}
81
if(pb)
82![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
83
bx[k]=b[i];
84
k++;
85
}
86
}
87
strcpy(anz,add(az,bz));
88
l=strlen(ax);
89
for(i=strlen(ax);i>=0;i--)
90![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
91
ax[i]=ax[i-1];
92
}
93
ax[0]='1';
94
a[l+1]='\0';
95
l=strlen(bx);
96
for(i=l;i>=0;i--)
97![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
98
bx[i]=bx[i-1];
99
}
100
bx[0]='1';
101
b[l+1]='\0';
102
if(strlen(ax)!=strlen(bx))
103![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
104
lb1=strlen(ax);
105
lb2=strlen(bx);
106
if(lb1>lb2)
107![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
108
for(i=lb2;i<lb1;i++)
109![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
110
bx[i]='0';
111
}
112
bx[i]='\0';
113
}else
114![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
115
for(i=lb1;i<lb2;i++)
116![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
117
ax[i]='0';
118
}
119
ax[i]='\0';
120
}
121
}
122
strcpy(anx,add(ax,bx));
123
l2=strlen(bx)>strlen(ax)?strlen(bx):strlen(ax);
124
if(anx[0]=='2'&&strlen(anx)==l2)
125![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
126
l=strlen(anx);
127
for(i=0;i<l;i++)
128![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
129
anx[i]=anx[i+1];
130
}
131
anx[i]='\0';
132
}else
133![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
134
l=strlen(anx);
135
for(i=0;i<l;i++)
136![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
137
anx[i]=anx[i+1];
138
}
139
anx[i]='\0';
140
strcpy(anz,add(anz,"1"));
141
}
142
l=strlen(anx);
143
for(i=l-1;i>=0;i--)
144![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
145
if(anx[i]!='0')
146![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
147
break;
148
}else
149![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
150
anx[i]='\0';
151
}
152
}
153
l=strlen(anz);
154
for(i=0;i<l;i++)
155![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
156
if(anz[i]!='0')
157![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
158
break;
159
}else
160![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
161
for(j=0;j<l;j++)
162![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
163
anz[j]=anz[j+1];
164
}
165
i--;
166
anz[j]='\0';
167
}
168
}
169
if(!anz[0])
170![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
171
anz[0]='0';
172
anz[1]='\0';
173
}
174
if(anx[0])
175
printf("%s.%s\n",anz,anx);
176
else
177
puts(anz);
178
}
179
}
180![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
posted on 2009-01-27 14:11
混沌的云 阅读(483)
评论(0) 编辑 收藏 引用