Problem Type : Number Theory
#include<iostream>
#include<cstring>
#include<iostream>
#include<string>
#include<cstdlib>
#include<sstream>
#include<cctype>
#define MAX 2147483647
using namespace std;
int main()
{
char ch[1000],des[1000];
long double a,b,sum;
char c;
while(cin >>ch >> c >> des)
{
cout << ch <<" " <<c << " " <<des <<endl;
a = atof(ch);
b = atof(des);
//printf("%.0lf %c %.0lf\n",a,c,b);
if(c=='+')
{
sum=a+b;
}
else if(c=='*')
{
sum=a*b;
}
if(a>MAX){
cout << "first number too big" << endl;
}
if(b>MAX)
{
cout <<"second number too big" <<endl;
//printf("result too big\n");
}
if(sum>MAX)
{
cout <<"result too big" <<endl;
}
}
}
#include<iostream>
#include<cstring>
#include<iostream>
#include<string>
#include<cstdlib>
#include<sstream>
#include<cctype>
#define MAX 2147483647
using namespace std;
int main()
{
char ch[1000],des[1000];
long double a,b,sum;
char c;
while(cin >>ch >> c >> des)
{
cout << ch <<" " <<c << " " <<des <<endl;
a = atof(ch);
b = atof(des);
//printf("%.0lf %c %.0lf\n",a,c,b);
if(c=='+')
{
sum=a+b;
}
else if(c=='*')
{
sum=a*b;
}
if(a>MAX){
cout << "first number too big" << endl;
}
if(b>MAX)
{
cout <<"second number too big" <<endl;
//printf("result too big\n");
}
if(sum>MAX)
{
cout <<"result too big" <<endl;
}
}
}
No comments:
Post a Comment