Problem link:: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2525
soliution ::
#include<bits/stdc++.h>
using namespace std;
int main()
{
map< char,int >mp;
int n,ans;
string s;
mp['a']=1,mp['b']=2,mp['c']=3,mp['d']=1,mp['e']=2,mp['f']=3,mp['g']=1,mp['h']=2,mp['i']=3,mp['j']=1,mp['k']=2,mp['l']=3,mp['m']=1;
mp['n']=2,mp['o']=3,mp['p']=1,mp['q']=2,mp['r']=3,mp['s']=4,mp['t']=1,mp['u']=2,mp['v']=3,mp['w']=1,mp['x']=2,mp['y']=3,mp['z']=4;
mp[' ']=1,mp['\n']=0;
cin>>n;
getchar();
for(int i=0;i<n;i++)
{
ans=0;
getline(cin,s);
for(int i=0;i<s.size();i++)
{
ans=ans+mp[s[i]];
}
cout<<"Case #"<<i+1<<": "<<ans<<endl;
}
return 0;
}
/*this problem solution is solved with mapping if you don't know mapping then you will fail to undrstand so stay with us to know about mapping */
/* if you don't know about cin && cout put scanf instead of cin && printf instead of cout. Both works the same. */
No comments:
Post a Comment