[Home|Training|Problems|Contests|C Language] | [Login|Register] |
New post Show post Search forum |
Read topic
mark
2015-09-29 16:41:35 cmer
#include <stdio.h>
#include <math.h> #include<string.h> int main(){ int n,j=0,a,b=1,t,i; char o[20]; char p[20]; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%s",o); for(t=0;t<=strlen(o)-2;t++) p[t]=o[t+2]; for(t=0;t<=strlen(o);t++) if (o[t]=='('){j=1;break;} if(j==0){for (t=1;t<=(strlen(o)-2);t++) b*=10; sscanf(p,"%d",&a); for (t=2;t<=b;t++) {while ((a%t==0)&&(b%t==0)) {a=a/t; b=b/t;} } printf("%d/%d\n",a,b); b=1; } if(j==1){for } while(1); }
Re:mark
2015-10-03 12:28:11 cmer
#include <stdio.h>
#include <math.h> #include<string.h> int main(){ int n,j=0,a,b=1,t,i,v; int fk,k,cfk,ck,b1=0,b2=0; char o[20],p[20],fk1[20]={0},k1[20]={0}; scanf("%d",&n); for(i=1;i<=n;i++){ j=0; scanf("%s",o); for(t=0;t<=strlen(o)-2;t++) p[t]=o[t+2]; for(t=0;t<=strlen(o);t++) if (o[t]=='('){j=1;break;} if(j==0){ a=1;b=1; for (t=1;t<=(strlen(o)-2);t++) b*=10; sscanf(p,"%d",&a); //printf("%d/%d\n",a,b); for (t=2;t<=b/2;t++) {while ((a%t==0)&&(b%t==0)) {a=a/t; b=b/t;} } printf("%d/%d\n",a,b); } if(j==1){ a=1;b=1; b1=0;b2=0; fk=t-2; for(t=0;t<=strlen(o);t++) if (o[t]==')') break; k=t-fk-3; v=0; for(t=0;t<=strlen(o)-2;t++){ if(o[t+2]!='(') {fk1[v]=o[t+2];v++;} } for(t=0;t<=strlen(o)-2;t++){ if (o[t+2]=='(') break; k1[t]=o[t+2]; } sscanf(fk1,"%d",&cfk); if (t!=0) sscanf(k1,"%d",&ck); else ck=0; a=cfk-ck; for(t=0;t<k;t++){ b1=b1+9*pow(10,t); } b2=pow(10,fk); b=b1*b2; //printf("%d/%d\n",a,b); for (t=2;t<=b/2;t++) {while ((a%t==0)&&(b%t==0)) {a=a/t; b=b/t;} } printf("%d/%d\n",a,b); } } return 0; } 超时TAT Reply
|