-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathString_T1_Q4.c
More file actions
80 lines (79 loc) · 1.33 KB
/
String_T1_Q4.c
File metadata and controls
80 lines (79 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<stdio.h>
#include<string.h>
int main()
{
char str[100];
int count=0,x=0,y=0,flag1=0,flag2=0,flag3=0;
printf("Enter the string: ");
scanf("%s",str);
for(int i=0; i<strlen(str); i++)
{
if(str[i]=='0')
{
x+=1;
}
}
int arr[x+1];
for(int j=0; j<strlen(str); j++)
{
if(str[j]=='0')
{
flag3=1;
flag2=1;
if(count==0)
{
continue;
flag1=1;
}
else
{
arr[y]=count;
count=0;
y+=1;
flag1=1;
}
}
else if(str[j]=='1')
{
count+=1;
flag2=0;
}
}
if(flag1==1)
{
if(str[0]=='0')
{
for(int l=0; l<x-1; l++)
{
printf("%d ",arr[l]);
}
}
else
{
for(int l=0; l<x; l++)
{
printf("%d ",arr[l]);
}
}
}
else
{
arr[0]=count;
printf("%d",arr[0]);
}
if(flag2==1)
{
flag2==1;
}
else
{
if(flag3==0)
{
flag3=0;
}
else
{
printf("%d",count);
}
}
}