View Code of Problem 3494

#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <vector>
#include <set>
using namespace std;
int gcd(int a,int b){
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main() {
	int a,b,c,d;
	char o;
	while(scanf("%d/%d%c%d/%d",&a,&b,&o,&c,&d)!=EOF){
		a*=d;
		c*=b;
		int zi,mu;
		mu=b*d;
		if(o=='+')
			zi=a+c;
		else zi=a-c; 
		int temp=gcd(abs(zi),mu);
		if(zi==0)
			cout<<0<<endl;
		else 
			printf("%d/%d\n",zi/temp,mu/temp);
	} 
        return 0;
}
/*
F:\temp\22473254.6784\Main.cc: In function 'int main()':
F:\temp\22473254.6784\Main.cc:17: error: 'scanf' was not declared in this scope
F:\temp\22473254.6784\Main.cc:17: error: 'EOF' was not declared in this scope
F:\temp\22473254.6784\Main.cc:29: error: 'printf' was not declared in this scope
*/

Double click to view unformatted code.


Back to problem 3494