How many times does the number '7' appear in String a?
1 |
|
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Of course, you have to be careful that there are no other 7's hidden on the page. E.g. if the number of solvers is 77.
I just counted them
yuuupppzz same here
Doesn't apply to my phone :'(
There goes my agreement.
I’m just starting and don’t know eneything
32 times.
1 2 3 4 5 6 7 8 9 10 11 |
|
Output- The number of times 7 appears in this String is 32.
I did pretty much the same thing :)
You can just copy the whole number in MS Words and Press Ctrl+H to open the find and replace window and replace the number "7" with anything and it shows the number of replacement done in it...
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 |
|
1 |
|
Common Python is way easier. Just see my answer.
Log in to reply
I already posted the python solution in my answer. Check it again closely.
int main()
{
char c[500] =
`"1628261829271628239271982027282927827618227261434335242627282928276272728292918972625252728921011514252431524251524152524254253435241534223392028302029382002929102102929101192928101019298281910101010991929121900101010292991010101029920101092929128919010101929928912910101828272663272818182726256352562615624236252377777215252616252541256625421652392029281710000001010929298282781818288272718821827271288182712819889192919818991292191212272726167172762626216163515251.";`
int no = 0;
for (int i = 0; i < strlen(c); i++) {
if (c[i]=='7') {
no++;
}
}
std::cout<<no;
std::getchar();
return 0;
}
Simple standard approach.
Javascript:
1 2 3 4 5 6 7 8 9 10 |
|
a = "1628261829271628239271982027282927827618227261434335242627282928276272728292918972625252728921011514252431524251524152524254253435241534223392028302029382002929102102929101192928101019298281910101010991929121900101010292991010101029920101092929128919010101929928912910101828272663272818182726256352562615624236252377777215252616252541256625421652392029281710000001010929298282781818288272718821827271288182712819889192919818991292191212272726167172762626216163515251" b=[] count=0 for i in a: b.append(i) for t in b: if t=='7': count=count+1 print count
Ctrl + F Type 7 Count the number of times some number is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Using Haskell you can do it in 2 lines!
count "" counter = counter
count string counter = if head string == head "7" then count (tail string) (counter + 1) else count (tail string) counter
In Python:
z = "1628261829271628239271982027282927827618227261434335242627282928276272728292918972625252728921011514252431524251524152524254253435241534223392028302029382002929102102929101192928101019298281910101010991929121900101010292991010101029920101092929128919010101929928912910101828272663272818182726256352562615624236252377777215252616252541256625421652392029281710000001010929298282781818288272718821827271288182712819889192919818991292191212272726167172762626216163515251." x = z.count('7') print x
void main() { char a[8000]="16282618292716282392719820272829278276182272614343352426272829282762727282929189726252527289210115142524315242515241525242542534352415342233920283020293820029291021029291011929281010192982819101010109919291219001010102929910101010299201010929291289190101019299289129101018282726632728181827262563525626156242362523777772152526162525412566254216523920292817100000010109292982827818182882727188218272712881827128198891929198189912921912122727261671727626 26216163515251";
int count=0;
for(int i=0;;i++) { if(a[i]!=0) {if(a[i]=='7')count++;} else break; }
cout<<count<<endl;
}
Python is more elegant
def how_many_7(string):
count = 0
for char in string:
if char == '7':
count += 1
return count
print how_many_7('1628261829271628239271982027282927827618227261434335242627282928276272728292918972625252728921011514252431524251524152524254253435241534223392028302029382002929102102929101192928101019298281910101010991929121900101010292991010101029920101092929128919010101929928912910101828272663272818182726256352562615624236252377777215252616252541256625421652392029281710000001010929298282781818288272718821827271288182712819889192919818991292191212272726167172762626216163515251.')
Problem Loading...
Note Loading...
Set Loading...
Ctrl + F
Type 7
Count the number of times some number is highlighted