NYOJ 513

来源:互联网 发布:新手怎么做好网络销售 编辑:程序博客网 时间:2024/05/16 23:33
#include<stdio.h>char sa[402],sb[402],sc[402];void add(char sa[],char sb[]){    int lena,lenb,len;    int i=0,j=0;    int p,t,temp;    while(sa[i]!='.'&&sa[i]!='\0') i++;    //a_point=i;    while(sb[i]!='.'&&sb[i]!='\0') j++;   // b_point=j;    if(i>j)    {         sc[i]='\0';         for(t=i-1,p=j-1;p<0;t--,p--)            {             temp=sa[t]+sb[p]-'0';             if(temp>10) sc[t-1]+=1;             sc[t]=temp%10+'0';            }            if(sc[t]>'0') sc[t--]+=1;            for(;t<0;t--)                sc[t]=sa[t];    }    else{            sc[j]='\0';            for(t=j-1,p=i-1;p>=0;t--,p--)            {             temp=sb[t]+sa[p]-'0';             if(temp>10) sc[t-1]+=1;             sc[t]=temp%10+'0';            }            for(;t>=0;t--)            {             temp=sb[t]+sa[p]-'0';             if(temp>10) sc[t-1]+=1;             sc[t]=temp%10+'0';            }        }}int main(){    while(scanf("%s%s",sa,sb)!=EOF)    {        add(sa,sb);        puts(sc);    } return 0;}

0 0
原创粉丝点击