jindal.manik
BAN USER#include<cstdio>
#include<cstring>
char explorestring(char *a, int k)
{
int count,i,j,len = strlen(a);
char curr_char;
for(i=0;i<len && k > 0;i++)
{
if(a[i]>96)
{
curr_char = a[i];
k--;
}
else if(a[i] < 58)
{
count = a[i] - 48;
for(j=i+1;a[j] < 58 && j<len;j++)
{
count = count *10;
count = count + a[j] -48;
}
k = k - count + 1 ;
i=j-1;
}
}
return curr_char;
}
int main()
{
char a[100];
scanf("%s",a);
int k;
scanf("%d",&k);
printf("%c",explorestring(a,k));
}
i hope this works. Pls give me some testcases it might not work for if u think.
- jindal.manik October 26, 2012okay. I havent understood what u both talked about. I'm sorry.
But my take on the question was:
a queue with the Data structure :
struct node
{
int data;
node *order;
node *predecessor;
node *successor;
};
now 3 pointers pointing to start,end and the max position.
the nodes will be arranged in a descending order, with the help of an appropriate add function.
what say ?
#include<cstdio>
#include<cstring>
#include<cstdlib>
int main()
{
char a[100];
scanf("%s",a);
int i,t,len = strlen(a);
for(i=1,t=0;i<len;i++)
{
if(a[i] != a[t])
{
if(i-t > 1)
{
a[i-1] = i-t;
if(a[i-1] > 9)
{
a[i-2] = 127;
}
}
t = i;
}
}
if(t==0)
{
if(len<10)
{
a[1] = len + 48;
a[2] = 0;
}
else
{
a[1] = len/10 + 48;
a[2] = len%10 + 48;
a[3] = 0;
}
printf("%s",a);
exit(0);
}
else
{
if(len-t>1)
{
a[len-1] = len - t;
if(len - t > 9)
{
a[len-2] = 127;
}
}
}
int c;
for(i=0,c=0;i<len;i++)
{
if(a[i] < 10)
{
c = c+ a[i] - 2;
}
else if(a[i] == 127)
{
c = c + a[i+1] - 3;
}
a[i-c] = a[i];
}
int nlen = len - c;
a[nlen] = 0;
for(i=0;i<nlen;i++)
{
if(a[i] < 10 )
{
a[i] = a[i] + 48;
}
else if(a[i] == 127)
{
a[i] = a[i+1]/10 + 48;
a[i+1] = a[i+1]%10 + 48;
}
}
for(i=0,c=0;i<nlen-1;i++)
{
if(a[i]>96 && a[i+1] > 96)
{
c++;
}
}
if(a[nlen-1] > 96)
{
c++;
}
int offset = c;
if(len<nlen+c || c==0)
{
printf("%s",a);
exit(0);
}
if(a[nlen-1] > 96)
{
a[nlen+c-1]=49;
c--;
a[nlen+c-1] = a[nlen-1];
}
for(i=1;i<nlen;i++)
{
if(a[nlen-1-i] > 96 && a[nlen-i] > 96)
{
a[nlen+c-1 - i] = 49;
c--;
}
a[nlen+c-1 - i] = a[nlen-1 - i];
}
a[nlen+offset] = 0;
printf("%s",a);
}
As far as I can think this will work, absolutely Inspace. If it doesnt work for some testcases give me those cases. Thank You in Advance
- jindal.manik October 26, 2012has to be done in space !
- jindal.manik October 26, 2012I dont know. But all this; is it just not the purpose of a max heap ?
- jindal.manik October 25, 2012
I think at the best optimisation it should print a1b2c3 if it can be done inplace
- jindal.manik November 05, 2012