Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

PBT Coding (only coding )

#WAIT FOT THE MCQ  

UPLOADING ...

PROGRAMMING 

1.

 Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the
given n numbers differs from the others. Bob observed that one number usually differs from the others
in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers
finds one that is different in evenness.
Input Format
The first line contains integer n — amount of numbers in the task.
The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that
exactly one of these numbers differs from the others in evenness.
Output Format
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the
input order.
Constraints
(3 ≤ n ≤ 100)

 

C++ CODE:

#include <iostream>
using namespace std;
int main()
{
    int n,i,j=0,k=0,a,b;
    cin >> n;
     int*p = new int[n];
     for (i = 0; i < n; i++)
    {
        cin >> p[i];
         if (p[i] % 2 == 0)
        {
             j++; if (j == 1)a = i+1;
        }
         else { k++; if (k == 1)b = i+1; }
    }
     if (k == 1)cout << b<<endl;
    else cout << a << endl;

}

*******************************************************************************

2.

One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep,
and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight
she imagined that all dragons were here to steal her, and she was fighting them off. Every k-th dragon
got punched in the face with a frying pan. Every l-th dragon got his tail shut into the balcony door.
Every m-th dragon got his paws trampled with sharp heels. Finally, she threatened every n-th dragon to
call her mom, and he withdrew in panic.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a
total of d dragons?
Input Format
Input data contains integer numbers k, l, m, n and d, each number in a separate line.
Constraints
(1 ≤ k, l, m, n ≤ 10, 1 ≤ d ≤ 10^5)
Output Format
Output the number of damaged dragons.

 

C CODE:

 #include<stdio.h>
int main()
{
    int k,i,l,m,n,d,c=0;
    scanf("%d%d%d%d%d",&k,&l,&m,&n,&d);
    for(i=1;i<=d;i++)
    {
        if(i%k==0||i%l==0||i%m==0||i%n==0)
        {
            c++;
        }
    }
printf("%d",c);
return(0);
    
}

********************************************************************************

3.

Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his
mother. He immediately decided to give it to somebody else as what can be more pleasant than giving
somebody gifts. And on this occasion he organized a New Year party at his place and invited n his
friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody
else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends
exchanging gifts while he does not participate in the process. He numbered all his friends with integers
from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also
remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend i the number of a friend who has given him a gift.
Input Format
The first line contains one integer n— the quantity of friends Petya invited to the party.
The second line contains n space-separated integers: the i-th number is pi — the number of a friend
who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is
possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends
gave the gifts to themselves.
Constraints
(1 ≤ n ≤ 100)
Output Format
Print n space-separated integers: the i-th number should equal the number of the friend who gave a
gift to friend number i.

 

C++ CODE:

 

#include<iostream>
using namespace std;
int main()
{
    int n,a[102],b[102];
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        if (i == a[i]) b[i] = i;
        if (i != a[i])  b[a[i]] = i;
    }
    for (int j = 1; j < n; j++)
        cout << b[j] <<" ";
        cout << b[n];
    return 0;
}
 

********************************************************************************

 

 

Post a Comment

Previous Post Next Post