Posts

Showing posts from October, 2021

Find Remainder

                               Find Remainder Write a program to find the remainder when an integer  A  is divided by an integer  B . Input The first line contains an integer  T , the total number of test cases. Then  T  lines follow, each line contains two Integers  A  and  B . Output For each test case, find the remainder when  A  is divided by  B , and display it in a new line. Constraints 1  ≤   T   ≤  1000 1  ≤   A,B   ≤  10000 Example Input 3 1 2 100 200 40 15 Output 1 100 10 Program Code #include <iostream> using namespace std; int main() { int n; cin>>n; int a,b; for(int i=0;i<n;i++) { cin>>a>>b; cout<<a%b<<endl; } return 0; }

Sum of Digits Codechef Solution

                         Sum of Digits  You're given an integer  N . Write a program to calculate the sum of all the digits of  N . Input The first line contains an integer  T , the total number of testcases. Then follow  T  lines, each line contains an integer  N . Output For each test case, calculate the sum of digits of  N , and display it in a new line. Constraints 1  ≤   T   ≤  1000 1  ≤   N   ≤  1000000 Example Input 3 12345 31203 2123 Output 15 9 8 Program Code #include <iostream> using namespace std; int main() { int n; cin>>n; int digits; for(int i=0;i<n;i++) { cin>>digits; int rem,sum; sum=0; while(digits>0) { rem=digits%10; sum=sum+rem; digits=digits/10; } cout<...

Number Mirror Codechef Solution

                      Number Mirror Problem Statement Write a program that accepts a number,  n , and outputs the same. Input The only line contains a single integer. Output Output the answer in a single line. Constraints 0 ≤ n ≤ 10 5 Sample Input 123 Sample Output 123 Program Code #include <iostream> using namespace std; int main() { // your code goes here int number; cin>>number; cout<<number; return 0; }

Add two numbers Codechef Solution

                          Add two numbers Problem Statement Every problem starts with a Problem Statement. It tells you in detail about the task to be solved. Usually, although not necessarily, it is accompanied with a story. As a competitive programmer, it is your job to break the problem statement and figure out exactly what it is asking. Shivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program. The task is very simple: given two integers A and B, write a program to add these two numbers and output it. Input This section tells you the format in which your program should receive the input. The first line contains an integer  T , the total number of test cases. Then follow  T  lines, each line contains two Integers  A  and  B . Output This section tells us the format in which your program should give the o...

Codechef's Enormous Input Test Solution

                                                 Enormous Input Set  The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the  enormous Input/Output  warning. You are expected to be able to process at least 2.5MB of input data per second at runtime. Input The input begins with two positive integers n k (n, k<=10 7 ). The next n lines of input contain one positive integer t i , not greater than 10 9 , each. Output Write a single integer to output, denoting how many integers t i  are divisible by k. Example Input: 7 3 1 51 966369 7 9 999996 11 Output: 4 Program Code #include <bits/stdc++.h> using namespace std; // Usually, you can use scanf/printf in C++. // However, if you want to use cin/cout, it is usually slow. // To mak...

Codechef's ATM problem Solution

                                                      ATM Pooja would like to withdraw  X  $US from an ATM. The cash machine will only accept the transaction if  X  is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US. Calculate Pooja's account balance after an attempted transaction. Input Positive integer 0 <  X  <= 2000 - the amount of cash which Pooja wishes to withdraw. Nonnegative number 0<=  Y  <= 2000 with two digits of precision - Pooja's initial account balance. Output Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to...