Responsive Ads Here

Wednesday 10 May 2017

ALCATRAZ1 - SUM OF DIGITS

problem id :-http://www.spoj.com/problems/ALCATRAZ1/

code:-

#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
string str;
cin>>str;
long long sum=-48*str.length();
int i=0;
while(str[i]!='\0')
{
sum+=str[i];
++i;
}
cout<<sum<<'\n';
}
return 0;
}

No comments:

Post a Comment