-
Notifications
You must be signed in to change notification settings - Fork 9
/
Least Occurring Digits.c
156 lines (142 loc) · 2.29 KB
/
Least Occurring Digits.c
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
A series of N integers is passed as input.
The program must print the least occurring digit(s) in series of integers in ascending order.
Example Input/Output 1:
Input:
35 81 78 84 53
Output:
1 4 7
Example Input/Output 2:
Input:
12 21 68 55 71 29 60 879
Output:
0
#include<stdio.h>
#include <stdlib.h>
int main()
{
int a[10]={0,1,2,3,4,5,6,7,8,9},count[10],i=0,j,d;
long int n;
int flag=0,pos=0;
for(i=0;i<10;i++)
count[i]=0;
while(scanf("%ld ",&n)>0)
{
while(n!=0)
{
d=n%10;
for(i=0;i<10;i++)
{
if(d==a[i])
{
count[i]++;
break;
}
}
n/=10;
}
}
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(count[i]>count[j])
{
d=a[i];
a[i]=a[j];
a[j]=d;
d=count[i];
count[i]=count[j];
count[j]=d;
}
}
if(count[i]!=0 && flag==0)
{
pos=i;
flag=1;
}
if(count[i]==count[pos] && flag==1)
printf("%d ",a[i]);
}
}
Input:
319026 9562421219901 60366 3454768
Output:
7 8
(or)
#include<stdio.h>
#include <stdlib.h>
int main()
{
long long int a[1000],size=0,count[10]={0},min=1000;
while(scanf("%lld",&a[size])==1)
{
long long int x=a[size];
while(x>0)
{
int y=x%10;
count[y]++;
x/=10;
}
size++;
}
for(int i=0;i<10;i++)
{
if(count[i]<min&&count[i]!=0)
min=count[i];
}
for(int i=0;i<10;i++)
if(count[i]==min)
printf("%d ",i);
}
(0r)
#include<stdio.h>
#include <stdlib.h>
int main()
{
char a[10000];
int b[10],i,j,s=1000;
scanf("%[^\n]s",a);
for(i=0;i<10;i++)
b[i]=0;
for(i=0;i<strlen(a);i++)
{
b[a[i]-48]++;
}
for(i=0;i<10;i++)
{
if(b[i]<s && b[i]>0)
s=b[i];
}
for(i=0;i<10;i++)
{
if(b[i]==s)
printf("%d ",i);
}
}
(or)
#include<stdio.h>
#include <stdlib.h>
int main()
{
int count[11]={0};
long a;
int min=1000;
while(scanf("%ld ",&a)>0)
{
while(a!=0)
{
++count[a%10];
a=a/10;
}
}
for(int i=0;i<11;i++)
{
if(min>count[i]&&count[i]>0)
min=count[i];
}
for(int i=0;i<11;i++)
{
if(count[i]==min)
printf("%d ",i);
}
}