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;
}
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