This is an old revision of the document!
https://projecteuler.net/archives
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left.
NOTE: String letters are case-sensitive.
Input Format
The first line of input contains the original string. The next line contains the substring.
Constraints
Each character in the string is an ascii character.
Output Format
Output the integer number indicating the total number of occurrences of the substring in the original string.
Sample Input
ABCDCDC CDC
Sample Output
2
Concept
Some string processing examples, such as these, might be useful. There are a couple of new concepts: In Python, the length of a string is found by the function len(s), where
is the string. To traverse through the length of a string, use a for loop:
for i in range(0, len(s)):
print (s[i])
A range function is used to loop over some length:
range (0, 5)
Here, the range loops over to . is excluded.
Consider a list (list = []). You can perform the following commands:
insert i e: Insert integer
at position . print: Print the list. remove e: Delete the first occurrence of integer . append e: Insert integer
at the end of the list. sort: Sort the list. pop: Pop the last element from the list. reverse: Reverse the list.
Initialize your list and read in the value of followed by lines of commands where each command will be of the
types listed above. Iterate through each command in order and perform the corresponding operation on your list.
Input Format
The first line contains an integer, , denoting the number of commands. Each line of the
subsequent lines contains one of the commands described above.
Constraints
The elements added to the list must be integers.
Output Format
For each command of type print, print the list on a new line.
Sample Input 0
12 insert 0 5 insert 1 10 insert 0 6 print remove 6 append 9 append 1 sort print pop reverse print
Sample Output 0
[6, 5, 10] [1, 5, 9, 10] [9, 5, 1]
Task Given an integer,
, perform the following conditional actions:
If
is odd, print Weird If is even and in the inclusive range of to , print Not Weird If is even and in the inclusive range of to , print Weird If is even and greater than
, print Not Weird
Input Format
A single line containing a positive integer,
.
Constraints
Output Format
Print Weird if the number is weird; otherwise, print Not Weird.
Sample Input 0
3
Sample Output 0
Weird
Explanation 0
is odd and odd numbers are weird, so we print Weird.
Sample Input 1
24
Sample Output 1
Not Weird
Explanation 1
and is even, so it isn't weird. Thus, we print Not Weird.
