#include <bits/stdc++.h>
#define ms(a,b) memset(a,b,sizeof(a))
#define pb(a) push_back(a)
#define db double
#define ft float
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define sz(x) x.size()
#define qu queue
#define pqu priority_queue
#define vc vector
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define all(x) x.begin(),x.end()
#define CIN ios_base::sync_with_stdio(0); cin.tie(0)
#define loop0(i,n) for(int i=0;i<n;i++)
#define loop1(i,n) for(int i=1;i<=n;i++)
#define stlloop(x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define case(z,x) cout<<"Case "<<i<<": "<<x<<endl
#define case(z) cout<<"Case "<<z<<": "
#define PI 3.14159265358979323846264338328
#define valid(tx,ty) tx>=0 && tx<r && ty>=0 && ty<c
#define MAX 2000
/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
//const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
//const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
/*------------------------------------------------*/
using namespace std;
int main()
{
CIN;
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
string n;
ll a,b,c,r,sum;
while(cin>>n && n!="0")
{
sum=0;
loop0(i,sz(n))
{
a=sz(n)-i;
b=pow(2,a);
c=b-1;
r=(n[i]-'0')*c;
sum=sum+r;
}
cout<<sum<<endl;
}
return 0;
}
Category String Manipulation
UVa – 12403 – Save Setu
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i,t;
long long int taka,total=0;
string s1;
cin>>t;
for(i=0;i<t;i++)
{
cin>>s1;
if(s1=="donate")
{
cin>>taka;
total=total+taka;
}
else if(s1=="report")
{
cout<<total<<endl;
}
}
return 0;
}
UVa – 12289 – One-two-three
#include <iostream>
#include <string>
using namespace std;
int main()
{
int t,i,j,k,s_l,c,d;
string s,s1="one",s2="two",s3="three";
cin>>t;
for(k=0;k<t;k++)
{
cin>>s;
s_l=s.length();
if(s_l==3)
{
c=0;
d=0;
for(i=0,j=0;i<3;i++,j++)
{
if(s[i]==s1[j])
{
c++;
}
if(s[i]==s2[j])
{
d++;
}
}
if(c==2 || c==3)
{
cout<<"1"<<endl;
}
if(d==2 || d==3)
{
cout<<"2"<<endl;
}
}
else if(s_l==5)
{
c=0;
for(i=0,j=0;i<5;i++,j++)
{
if(s[i]==s3[j])
{
c++;
}
}
if(c==4 || c==5)
{
cout<<"3"<<endl;
}
}
}
return 0;
}
UVa – 12250 – Language Detection
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i;
string s1;
for(i=1;;i++)
{
cin>>s1;
if(s1=="#")
{
break;
}
else
{
if(s1=="HELLO")
{
cout<<"Case "<<i<<": "<<"ENGLISH"<<endl;
}
else if(s1=="HOLA")
{
cout<<"Case "<<i<<": "<<"SPANISH"<<endl;
}
else if(s1=="HALLO")
{
cout<<"Case "<<i<<": "<<"GERMAN"<<endl;
}
else if(s1=="BONJOUR")
{
cout<<"Case "<<i<<": "<<"FRENCH"<<endl;
}
else if(s1=="CIAO")
{
cout<<"Case "<<i<<": "<<"ITALIAN"<<endl;
}
else if(s1=="ZDRAVSTVUJTE")
{
cout<<"Case "<<i<<": "<<"RUSSIAN"<<endl;
}
else
{
cout<<"Case "<<i<<": "<<"UNKNOWN"<<endl;
}
}
}
return 0;
}
UVa – 12626 – I love Pizza
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i,j,t,s_l,a,b,c,d,e,f,g,x;
string s;
cin>>t;
for(i=0;i<t;i++)
{
cin>>s;
a=0;
b=0;
c=0;
d=0;
e=0;
f=0;
g=0;
s_l=s.length();
for(j=0;j<s_l;j++)
{
if(s[j]=='M')
{
a++;
}
}
for(j=0;j<s_l;j++)
{
if(s[j]=='A')
{
b++;
}
}
for(j=0;j<s_l;j++)
{
if(s[j]=='R')
{
c++;
}
}
for(j=0;j<s_l;j++)
{
if(s[j]=='G')
{
d++;
}
}
for(j=0;j<s_l;j++)
{
if(s[j]=='I')
{
e++;
}
}
for(j=0;j<s_l;j++)
{
if(s[j]=='T')
{
f++;
}
}
x=0;
for(j=1;;j++)
{
if(a>=1*j && b>=3*j && c>=2*j && d>=1*j && e>=1*j && f>=1*j)
{
x++;
}
else
{
break;
}
}
cout<<x<<endl;
}
return 0;
}