Compete

I can't fall down before I die

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  11 Posts :: 3 Stories :: 2 Comments :: 0 Trackbacks

常用链接

留言簿(2)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

#include<iostream>
#include
<string>
#include
<cmath>
using namespace std;

int Case;
char in[400];


int main()
{
    cin
>>Case;
    
int pos;
    
int i,j,k,m,n,len,cur,sumint_left,sumint_right,sumx_left,sumx_right;
    
float sumx,sumint;
    
float res;
    
bool left;
    
bool lastchar;
    
while(Case--)
    
{
        cin
>>in;
        len
=strlen(in);
        sumint_left
=0;
        sumint_right
=0;
        sumx_left
=0;
        sumx_right
=0;
        cur
=0;
        left
=1;
        
for(i=0;i<len;i++)
            
if(in[i]=='=')
                
break;
        pos
=i;
        lastchar
=1;
        
for(i=0;i<pos;i++)
        
{
            
if(in[i]=='x')
            
{
                
if(lastchar)
                    sumx_left
++;
                
else
                    sumx_left
--;
                i
++;
                
if(i==pos)
                    
break;
                
else if(in[i]=='+')
                    lastchar
=1;
                
else lastchar=0;
            }

            
else
            
{
                cur
=0;
                
for(j=i;j<pos&&in[j]>='0' && in[j]<='9';j++)
                
{
                    cur
*=10;
                    cur
+=in[j]-'0';
                }

                
if(j==pos)
                
{
                    
if(lastchar)
                        sumint_left
+=cur;
                    
else 
                        sumint_left
-=cur;
                    
break;
                }

                
else
                
{
                    
if(in[j]=='x')
                    
{
                        
if(lastchar)
                            sumx_left
+=cur;
                        
else 
                            sumx_left
-=cur;
                        j
++;
                        
if(j==pos)
                            
break;
                        
else if(in[j]=='+')
                                lastchar
=1;
                        
else lastchar=0;
                        i
=j;
                    }

                    
else
                    
{
                        
if(lastchar)
                            sumint_left
+=cur;
                        
else sumint_left-=cur;
                        
if(in[j]=='+')
                            lastchar
=1;
                        
else lastchar=0;
                        i
=j;
                    }

                }

            }

        }

        lastchar
=1;
        
for(i=pos+1;i<len;i++)
        
{
            
if(in[i]=='x')
            
{
                
if(lastchar)
                    sumx_right
++;
                
else sumx_right--;
                i
++;
                
if(i==len)
                    
break;
                
else if(in[i]=='+')
                    lastchar
=1;
                
else
                    lastchar
=0;
            }

            
else
            
{
                cur
=0;
                
for(j=i;j<len && in[j]<='9' && in[j]>='0';j++)
                
{
                    cur
*=10;
                    cur
+=in[j]-'0';
                }

                
if(j==len)
                
{
                    
if(lastchar)
                        sumint_right
+=cur;
                    
else
                        sumint_right
-=cur;
                    
break;
                }

                
else
                
{
                    
if(in[j]=='x')
                    
{
                        
if(lastchar)
                            sumx_right
+=cur;
                        
else 
                            sumx_right
-=cur;
                        j
++;
                        
if(j==pos)
                            
break;
                        
else    if(in[j]=='+')
                            lastchar
=1;
                        
else
                            lastchar
=0;
                        i
=j;
                    }

                    
else
                    
{
                        
if(lastchar)
                            sumint_right
+=cur;
                        
else
                            sumint_right
-=cur;
                        
if(in[j]=='+')
                            lastchar
=1;
                        
else 
                            lastchar
=0;
                        i
=j;
                    }

                }

            }

        }

    
//    cout<<sumx_left<<"        "<<sumx_right<<"         "<<sumint_left<<"        "<<sumint_right<<endl;
        if(sumx_left==sumx_right)
        
{
            
if(sumint_left==sumint_right)
                cout
<<"IDENTITY"<<endl;
            
else
                cout
<<"IMPOSSIBLE"<<endl;
        }

        
else
        
{
            sumx
=sumx_left-sumx_right;
            sumint
=sumint_right-sumint_left;
            res
=sumint/sumx;
            cout
<<floor(res)<<endl;
        }

    }

    
return 0;
}

posted on 2010-05-27 14:46 丁立洋 阅读(338) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理