2009-04-04 14:37:33來源不明

绝對值

/***********************************************/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
main()
{
 double ans;
 char x[100];
 int time=0;
 while(gets(x))
  {time++;
   int a,b,c,flag=0;
   int m=strlen(x);
   long long int temp=0,temp1=0;
   for(a=0;a<m;a++)
    {
     if(x[a]<=57&&x[a]>=48&&flag==0)
      flag=1;
     if(x[a]<=57&&x[a]>=48&&flag==1)
      {
       temp=temp*10+x[a]-48;
       flag=1;
      }
     if((x[a]<48||x[a]>57)&&flag==1)
      flag=2;
     if(flag==2&&x[a]<=57&&x[a]>=48) 
      temp1=temp1*10+x[a]-48;
    }
    if(m==1&&x[0]=='i') temp1=1;
    else
      if(x[m-1]=='i'&&(x[m-2]>57||x[m-2]<48))
       temp1=1;
    ans=sqrt(temp*temp+temp1*temp1);
    printf("%.3lf\n",ans);
  }
 return 0;
}