#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct {     char sign;//符号     char cardinal_num[10005];//基数     char S_sign;//科学计数符号,默认为E     int index;//指数 }Sn; void Input(Sn *num,char *inum); int Conversion(Sn num,char *cnum); int ctoi(char *num); int main(int argc,char *argv[]) {     Sn num;     char cnum[10002]={'\0'},inum[10002]={'\0'};     int flag;     gets(inum);     Input(&num,inum);     flag=Conversion(num,cnum);     if(flag==1)     {         printf("%s",cnum);     }     else     {         printf("-%s",cnum);     }     system("pause");     return 0; } int ctoi(char *num) {     int data=0,i=0,flag=0;     if(num[0]=='-')     {         flag=-1;     }     if((num[0]>='0'&&num[0]<='9')||num[0]=='+')     {         flag=1;     }     for(i=0;num[i]!='\0';i++)     {         if(num[i]>='0'&&num[i]<='9')         {             data=10*data+(num[i]-'0');         }     }     data=flag*data;     return data; } void Input(Sn *num,char *inum) {     int i,e=-1,j=0;     char *p=NULL,*pnum=inum;     num->sign=inum[0];     num->S_sign='E';     for(i=1;inum[i]!='\0';i++)     {                  if(inum[i]=='E')         {             e=i+1;             break;         }         if(inum[i]!='.')         {             num->cardinal_num[j]=inum[i];             j++;         }     }     num->cardinal_num[j]='\0';     p=pnum+e;     num->index=ctoi(p); } int Conversion(Sn num,char *cnum) {     int flag=0,all,point,i,j=0,zeronum;     int clen;     clen=strlen(num.cardinal_num);     if(num.sign=='+')     {         flag=1;     }     if(num.sign=='-')     {         flag=-1;     }     if(num.index>=0)     {         all=num.index+1;         point=1+num.index;         if(all>=clen)         {             for(i=0;i<all;i++)             {                 if(num.cardinal_num[i]>='0'&&num.cardinal_num[i]<='9')                 {                     cnum[i]=num.cardinal_num[j];                     j++;                 }                 else                 {                     cnum[i]='0';                 }             }         }         else         {             cnum[point]='.';             for(i=0;i<clen+1;i++)             {                 if(cnum[i]!='.')                 {                     cnum[i]=num.cardinal_num[j];                     j++;                 }             }         }     }     if(num.index<0)     {         cnum[0]='0';         cnum[1]='.';         zeronum=abs(num.index)-1;         all=clen+zeronum;         for(i=2;i<2+all;i++)         {             if(i<2+zeronum)             {                 cnum[i]='0';             }             else             {                 cnum[i]=num.cardinal_num[j];                 j++;             }         }     }     cnum[i]='\0';     return flag; }
点赞 评论

相关推荐

牛客网
牛客企业服务