PKU 2845 01000001

http://poj.org/problem?id=2845
2進数の足し算をしてその結果を出力。
易。

先頭の0の処理を見落として1WA。

string add(string a,string b){
  reverse(ALL(a));
  reverse(ALL(b));

  string ret;
  int c=0;
  rep(i,max(a.size(),b.size())){
    int t=c;
    if(i<a.size())t+=a[i]-'0';
    if(i<b.size())t+=b[i]-'0';
    c=t/2;
    t%=2;
    ret+=t+'0';
  }
  if(c)ret+='1';
  reverse(ALL(ret));
  int pos=0;
  while(pos<ret.size()-1 && ret[pos]=='0')++pos;
  return ret.substr(pos);
}

main(){
  int t;
  cin>>t;
  rep(i,t){
    string a,b;
    cin>>a>>b;
    cout<<i+1<<' '<<add(a,b)<<endl;
  }
}