ITeye博客

save

kongweile · 2010-03-30 15:44 · struts2 · 企业架构 · C · C++ · C# · Markdown

#include "stdafx.h"
#include "sstream"
#include "iostream"
#include "string"

using namespace std;

bool check(int n[],int d)
{
 int i,a=0,b=0;
 for(i=0;i!=d;++i)
 {
  a+=n[i];
 }
 for(i=d;i!=2*d;++i)
 {
  b+=n[i];
 }
 if(a==b)
  return true;
 return false;
}

int main()
{
 int i,r,n[21],t,c,d;
 string s;
 while(cin>>s)
 {
  c=0;
  d=s.length()/2;
  r=s.length();
  for(i=0;i!=r;++i)
  {
   stringstream ss(s.substr(i,1));
   ss>>t;
   n[i]=t;
  }

  while(!check(n,d))
  {
   ++c;
   ++n[r-1];

  }
 }
 return 0;
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。