| ||||||||||
| 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 <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
void fun(string t,int &a,int &b)
{
a=0,b=0;
t+="+";
int flag=1;
int sum=0;
bool you=false;
for(int i=0; i<t.size(); i++)
{
if(t[i]=='-')
{
if(you)
{
b+=flag*sum;
sum=0;
you= false;
}
flag=-1;
}
else if(t[i]=='+')
{
if(you)
{
b+=flag*sum;
sum=0;
you=false;
}
flag=1;
}
else if(t[i]=='x')
{
if(you)
{
a+=flag*sum;
you=false;
sum=0;
}
else
{
a+=flag;
}
}
else
{
you=true;
sum=sum*10+t[i]-'0';
}
}
}
void solve()
{
string a;
cin>>a;
int id=a.find("=");
int len=a.size();
string b,c;
b=a.substr(0,id);
c=a.substr(id+1,len);
int A,B,C,D;
fun(b,A,B);
fun(c,C,D);
if(A==C)
{
puts(B!=D?"IMPOSSIBLE":"IDENTITY");
return ;
}
int ans=(D-B)/(A-C);
if(ans<0&&(D-B)%(A-C)!=0)
ans--;
printf("%d\n",ans);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
solve();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator