Sunday, June 19, 2016

Uva 11530: Sms Typing.cpp


Problem link: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjXjp_StrTNAhWIro8KHauXBssQFggcMAA&url=https%3A%2F%2Fuva.onlinejudge.org%2Findex.php%3Foption%3Dcom_onlinejudge%26Itemid%3D8%26page%3Dshow_problem%26problem%3D2525&usg=AFQjCNGDCAdSikS28s2QwAUOJaRX_P3F3Q&sig2=U5v6MqcnrBRJiCBGidoQmw&bvm=bv.124817099,d.c2I

It is a problem of Adhoc catagory.I just used simple  implementation process. 
#include <bits/stdc++.h>
#define ll unsigned long long int
#define M 10000000
using namespace std;
int main()
{
ll c,cn;
string k[9]={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"," "};
cin>>cn;
string s;
getline(cin,s);
ll i=1;
while(cn--)
{ getline(cin,s);
c=0;
for(ll i=0; i<s.length(); i++)
{
for(ll j=0; j<9; j++)
{
for(ll l=0; l<k[j].length(); l++)
{
if(s[i]==k[j][l])
{c+=l+1;
//cout<<l+1<<endl;
}
}
}
}
cout<<"Case #"<<i<<": "<<c<<"\n";
i++;
}
}

No comments:

Post a Comment