ROWSOLD SOLUTION
2 posters
Page 1 of 1
ROWSOLD SOLUTION
- Code:
#include <stdio.h>
int main()
{
long long t,i,k,p1,p2,m,w,co,f;
scanf("%lld",&t);
char ch[1000005];
for(i=1;i<=t;i++)
{
p1=0,p2=0,w=0,co=0,m=0,f=0;
scanf("%s",ch);
for(k=0;k<strlen(ch);k++)
{
if(ch[k]=='1')
{
p1=k;
break;
}
}
for(k=strlen(ch)-1;k>=0;k--)
{
if(ch[k]=='0')
{
p2=k;
break;
}
}
//printf("%d %d\n",p1,p2);
m=0;
for(k=p2;k>=p1;k--)
{
if(ch[k]=='0')
{
co++;
if(f==0)
{
m++;
f=1;
}
}
else
{
w=w+co+m;
f=0;
}
}
printf("%lld\n",w);
}
return 0;
}
Re: ROWSOLD SOLUTION
#include<stdio.h>
#include<string.h>
int main()
{
int t;
scanf("%d",&t);
while(t>0)
{
int time=0,c=0,c1,j=0,k,l;
char s[100001];
scanf("%s",s);
l=strlen(s);
for(k=l-1;k>=0;k--)
{
if(j==0)
{
if(s[k]=='0')
j=k;
}
if(s[k]=='1')
c++;
}
while(c>0)
{
c1=0;
for(l=0;l<j;l++)
{
if(s[l]=='1'&&s[l+1]=='0')
c1++;
}
time+=c1;
for(l=0;l<j;l++)
{
if(s[l]=='1'&&s[l+1]=='0')
{
s[l]='0';
s[l+1]='1';
time++;
}
}
j--;
c--;
}
printf("%d\n",time);
t--;
}
return 0;
}
#include<string.h>
int main()
{
int t;
scanf("%d",&t);
while(t>0)
{
int time=0,c=0,c1,j=0,k,l;
char s[100001];
scanf("%s",s);
l=strlen(s);
for(k=l-1;k>=0;k--)
{
if(j==0)
{
if(s[k]=='0')
j=k;
}
if(s[k]=='1')
c++;
}
while(c>0)
{
c1=0;
for(l=0;l<j;l++)
{
if(s[l]=='1'&&s[l+1]=='0')
c1++;
}
time+=c1;
for(l=0;l<j;l++)
{
if(s[l]=='1'&&s[l+1]=='0')
{
s[l]='0';
s[l+1]='1';
time++;
}
}
j--;
c--;
}
printf("%d\n",time);
t--;
}
return 0;
}
iamdsc_0410- Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani
Similar topics
» SMARKET SOLUTION
» DISH OF LIFE SOLUTION
» CHEF AND DIGITS SOLUTION
» Similar Dishes Solution
» in ipl question.the test case 2nd is wrong.my solution is correct.
» DISH OF LIFE SOLUTION
» CHEF AND DIGITS SOLUTION
» Similar Dishes Solution
» in ipl question.the test case 2nd is wrong.my solution is correct.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|