Given a number N, print sum of all even numbers from 1 to N. #include<iostream> using namespace std; int main(){ /* Read input as specified in the question. * Print output as specified in the question. */ int sum,n; cin>>n; sum=0; for (int i=1;i<=n;i++){ if (i%2==0){ sum=sum+i; } } cout<<sum; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include<iostream> using namespace std; int main(){ /* Read input as specified in the question. * Print output as specified in the question. */ int sum,n; cin>>n; sum=0; for (int i=1;i<=n;i++){ ...
Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up. Input Format The first line contains . The second line contains an array of integers each separated by a space. Constraints Output Format Print the runner-up score. Sample Input 0 5 2 3 6 6 5 Sample Output 0 5 Explanation 0 Given list is . The maximum score is , second maximum is . Hence, we print as the runner-up score. ### OPTIMIZED ### from collections import Counter if __ name__ == '__main__' : n = int ( input ()) arr = map ( int , input () . split ()) lis = list ( Counter ( arr ) . keys ()) lis . sort () ...
For a given input string(str), write a function to print all the possible substrings. Substring A substring is a contiguous sequence of characters within a string. Example: "cod" is a substring of "coding". Whereas, "cdng" is not as the characters taken are not contiguous Input Format: The first and only line of input contains a string without any leading and trailing spaces. All the characters in the string would be in lower case. Output Format: Print the total number of substrings possible, where every substring is printed on a single line and hence the total number of output lines will be equal to the total number of substrings. Note: The order in which the substrings are printed, does not matter. Constraints: 0 <= N <= 10^6 Where N is the length of the input string. Time Limit: 1 second Sample Input 1: abc Sample Output 1: a ab abc b bc c Sample Input 2: co Sample Output 2: c co o #include <iostream> #include <cstring> us...
Comments
Post a Comment