/ Vijos / 讨论 / 问答 /

为什么同样的程序用C与C++交是不一样的错误

程序1230

#include

#include

int main()

{

char x[55];

int i,j=0,k=0,flag=1,sign=0;

gets(x);

for(i=0;i=strlen(x))&&(j==0)) {if(x[0]=='-') printf("F");printf("0");goto lack;}

if(i>=strlen(x)&&j!=0) {if(x[0]=='-') printf("F");sign=1;goto loop;}

k=0;flag=1;j=0;

for(i=0;x[i]!='.';i++)

{

if(x[i]=='-')

{

printf("%c",'F');

continue;

}

if((x[i]!='0')&&flag) {k=i;flag=0;}

if(!flag) j++;

}

if(j==0) {k=i;printf("%c",'0');}

loop: for(i=j;i>=1;i--,k++)

{

if(x[k]=='0')

{

if(x[k+1]!='0'&&x[k+1]!='.'&&!sign)

{

if((x[k-3]!='0'||x[k-2]!='0'||x[k-1]!='0')&&(i==5)) printf("%c%c",'W','0');

else printf("%c",'0');

continue;

}

if(x[k+1]!='0'&&sign&&x[k+1]!='\0')

{

if((x[k-3]!='0'||x[k-2]!='0'||x[k-1]!='0')&&(i==5)) printf("%c%c",'W','0');

else printf("%c",'0');

continue;

}

if(!sign&&x[k+1]=='.') continue;

if(sign&&x[k+1]=='\0') continue;

}

if(x[k]=='0'&&x[k+1]=='0') continue;

switch(i)

{

case 9:printf("%c%c",x[k],'Y');break;

case 8:printf("%c%c",x[k],'Q');break;

case 7:printf("%c%c",x[k],'B');break;

case 6:printf("%c%c",x[k],'S');break;

case 5:printf("%c%c",x[k],'W');break;

case 4:printf("%c%c",x[k],'Q');break;

case 3:printf("%c%c",x[k],'B');break;

case 2:printf("%c%c",x[k],'S');break;

case 1:printf("%c",x[k]);break;

}

}

if((x[k]=='.')&&(x[k+1]!='\0'))

{

printf("%c",'D');

for(i=k+1;x[i]!='\0';i++)

printf("%c",x[i]);

}

lack:printf("\n");

return(0);

}

0 条评论

目前还没有评论...