Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Why WA???晕死,m我还以为是million呢!!!/************************************************************************** * Problem: POJ 2256 Artificial Intelligence? * Copyright 2011 by Yan * DATE: * E-Mail: yming0221@gmail.com ************************************************************************/ #include <stdio.h> char cache[2000]; char op1[50]; char op2[50]; double dop1,dop2; int len; void get_op(int p1,int p2) { int index=p1; int op_index=0; int i; char tmp;/*存放单位字符*/ while(cache[++index]!='A'&& cache[index]!='W'&& cache[index]!='V') { op1[op_index++]=cache[index]; } op1[op_index]='\0'; tmp=op1[op_index-1]; if(tmp=='m'||tmp=='k'||tmp=='M') op1[op_index-1]='\0';/*从字符串中取出单位*/ sscanf(op1,"%lf",&dop1); switch (tmp) { case 'k':dop1=dop1*1000.0;break; case 'm':dop1=dop1*1000000.0;break; case 'M':dop1=dop1*1000000.0;break; } index=p2; op_index=0; while(cache[++index]!='A'&& cache[index]!='W'&& cache[index]!='V') { op2[op_index++]=cache[index]; } op2[op_index]='\0'; tmp=op2[op_index-1]; if(tmp=='m'||tmp=='k'||tmp=='M') op1[op_index-1]='\0';/*从字符串中取出单位*/ sscanf(op2,"%lf",&dop2); switch (tmp) { case 'k':dop2=dop2*1000.0;break; case 'm':dop2=dop2*1000000.0;break; case 'M':dop2=dop2*1000000.0;break; } } int main() { int n,i,j; int index[2];/*存放两个等号的位置*/ int cnt; double ans; scanf("%d ",&n); for(i=1;i<=n;i++) { gets(cache); /*puts(cache);*/ len=strlen(cache); cnt=0; for(j=0;j<len;j++) { if(cache[j]=='=') index[cnt++]=j; if(cnt==2) break; }/*扫描到两个等号*/ get_op(index[0],index[1]);/*获取操作数和操作*/ printf("Problem #%d\n",i); if( (cache[index[0]-1]=='U'&&cache[index[1]-1]=='I') || (cache[index[0]-1]=='I'&&cache[index[1]-1]=='U')) { printf("P=%.2fW\n\n",dop1*dop2); } else if( (cache[index[0]-1]=='P'&&cache[index[1]-1]=='I') || (cache[index[0]-1]=='I'&&cache[index[1]-1]=='P')) { if(cache[index[0]-1]=='P') printf("U=%.2fV\n\n",dop1/dop2); else printf("U=%.2fV\n\n",dop2/dop1); } else if( (cache[index[0]-1]=='U'&&cache[index[1]-1]=='P') || (cache[index[0]-1]=='P'&&cache[index[1]-1]=='U')) { if(cache[index[0]-1]=='P') printf("I=%.2fA\n\n",dop1/dop2); else printf("I=%.2fA\n\n",dop2/dop1); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator