Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:哦!亲!!七遍啊!!!!一定要注意是一个字符串!!!!!!!有木有!!!(附代码)

Posted by 1004131114 at 2014-08-01 20:22:41 on Problem 3979
In Reply To:哦!亲!!七遍啊!!!!一定要注意是一个字符串!!!!!!!有木有!!!(附代码) Posted by:1152230301 at 2011-07-01 20:47:21
> #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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator