Von Neuman Loves BInary see

#include
#include<string.h>
#include
using namespace std;
int main() {
int n,i;
cin>>n;
for(i=0;i<n;i++)
{string s;
cin>>s;
int sum=0;
int l;
l=s.length();
l=l-1;
for(int j=l;j>=0;j++)
{
sum=sum+int(s[j])*pow(2,l-j);
cout<<sum<<endl;
}

}
return 0;

}

where am i making mistake.

Hello @neeleshr628,

There are three mistakes in your program:

  1. The first is in the for loop.
    for(int j=l;j>=0;j++)
    This is causing TLE

  2. The place where you are executing the following statement:
    cout<<sum<<endl;
    This is causing wrong output.

  3. int(s[j])
    Converting character into string will give it’s ASCII number.
    Correction: (s[j]-β€˜0’).

I would suggest you to resolve it yourself.

Hope, this would help.
Give a like, if you are satisfied.