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 |
哦!亲!!七遍啊!!!!一定要注意是一个字符串!!!!!!!有木有!!!(附代码)#include<iostream> #include<math.h> using namespace std; int max(int a,int b){ int i=(a<b?a:b); while((b%i!=0)||(a%i!=0)){ i--; } return i; } int main() { int a,b,c,d,above,below,factor; char str[1000]; char oper; while((scanf("%s",&str))!=EOF){ a=str[0]-'0'; b=str[2]-'0'; oper=str[3]; c=str[4]-'0'; d=str[6]-'0'; //赋值 above=0; below=0; below=b*d; if(oper=='+') above=a*d+b*c; else above=a*d-b*c; if(above%below==0) printf("%d\n",above/below); else{ if(above*below<0){ printf("-"); above=abs(above); below=abs(below); } factor=max(above,below); above/=factor; below/=factor; printf("%d/%d\n",above,below); } } return 0; } 还有一次因为char开小了开成7那么大的,然后又有一次提交时忘改代码了 不要因为题简单就小瞧人家!!!! Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator