kush.udit
BAN USER
Comments (4)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
#include<iostream>
#include<string>
using namespace std;
string pattern[]={"","1","abc2","def3","ghi4","jkl5","mno6","pqrs7","tuv8","wxyz9"};
//string star=" ";
//string hash="#";
int main()
{
string keystroke;
cout<<"enter keystroke:";
cin>>keystroke;
int length=keystroke.length();
int i=0,j,cnt;
for(i=0;i<length-1;i++)
{
cnt=1;
if(keystroke[i]=='#')continue;
if (keystroke[i]=='*')
{cout<<" ";continue;}
j=keystroke[i]-'0';
while((keystroke[i]==keystroke[i+1])&&(i<length-1))
{
cnt++;i++;
}
if(cnt>pattern[j].length())cnt%=pattern[j].length();
if(cnt!=0)cout<<pattern[j][cnt-1];
else cout<<pattern[j][cnt];
// if(i==length-1)break;
}
if(i!=length)
cout<<pattern[keystroke[i]-'0'][0];
}
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
#include<cstdio>
- kush.udit July 29, 2013#include<iostream>
using namespace std;
int main()
{
int no[100]={0},cnt=0,x,y,n,xf,yf,cntf=0;
bool nohash[100]={false};
cout<<"enter the no of elements"<<endl;
cin>>n;
cout<<"enter the elements"<<endl;
for(int i=0;i<n;i++)
{
cin>>no[i];
nohash[no[i]]=true;
}
for(int i=0;i<100;i++)
{
if(nohash[i]==true)
{x=i;
while(nohash[i]==true)
{
cnt++;i++;
}
y=i-1;
}
if(cnt>cntf)
{
cntf=cnt;
xf=x;
yf=y;
}
cnt=0;
}
cout<<"range is"<<xf<<"to"<<yf<<endl;
}
//an O(n) soln. using hash table