Sunday, March 26, 2023

Aptitude test assistant programmer 2018

 #include <stdio.h>

#include <stdlib.h>

int main()

{

char str[100];

int i;

int space=0;

    printf("Enter a string\n");

    fgets(str,sizeof(str),stdin);

    i=0;

    while(i<=str[i]){

 if(str[i]==' '){

        space++;

    }

    i++;

}

printf("Total word count :%d" ,space+1);

 

    return 0;

}

Saturday, March 25, 2023

Codeforce Problem 1703A. YES or YES?

A. YES or YES?
 

There is a string  of length 3, consisting of uppercase and lowercase English letters. Check if it is equal to "YES" (without quotes), where each letter can be in any case. For example, "yES", "Yes", "yes" are all allowable.

Input

The first line of the input contains an integer  (1103) — the number of testcases.

The description of each test consists of one line containing one string  consisting of three characters. Each character of  is either an uppercase or lowercase English letter.

Output

For each test case, output "YES" (without quotes) if  satisfies the condition, and "NO" (without quotes) otherwise.

You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).

Example
input
Copy
10
YES
yES
yes
Yes
YeS
Noo
orZ
yEz
Yas
XES
output
Copy
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
Note

The first five test cases contain the strings "YES", "yES", "yes", "Yes", "YeS". All of these are equal to "YES", where each character is either uppercase or lowercase.

 


Solution in cpp


  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // Write C++ code here
  6. int t ;
  7. cin>>t;
  8. while(t--)
  9. {
  10. string s;
  11. cin>>s;
  12.  
  13. if((s[0]=='Y' or s[0]=='y') and (s[1]=='E' or s[1]=='e') and (s[2]=='s' or s[2]=='S'))
  14. {
  15. cout<<"YES"<<endl;
  16. }
  17. else cout<<"NO"<<endl;
  18. }
  19. return 0;
  20. }

Sunday, November 7, 2021

A. Arithmetic Array 1537A





time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

An array b of length k is called good if its arithmetic mean is equal to 1. More formally, if

b1++bkk=1.

Note that the value b1++bkk is not rounded up or down. For example, the array [1,1,1,2] has an arithmetic mean of 1.25, which is not equal to 1.

You are given an integer array a of length n. In an operation, you can append a non-negative integer to the end of the array. What's the minimum number of operations required to make the array good?

We have a proof that it is always possible with finitely many operations.

Input

The first line contains a single integer t (1t1000) — the number of test cases. Then t test cases follow.

The first line of each test case contains a single integer n (1n50) — the length of the initial array a.

The second line of each test case contains n integers a1,,an (104ai104), the elements of the array.

Output

For each test case, output a single integer — the minimum number of non-negative integers you have to append to the array so that the arithmetic mean of the array will be exactly 1.

Example
input
Copy
4
3
1 1 1
2
1 2
4
8 4 6 2
1
-2
output
Copy
0
1
16
1
Note

In the first test case, we don't need to add any element because the arithmetic mean of the array is already 1, so the answer is 0.

In the second test case, the arithmetic mean is not 1 initially so we need to add at least one more number. If we add 0 then the arithmetic mean of the whole array becomes 1, so the answer is 1.

In the third test case, the minimum number of elements that need to be added is 16 since only non-negative integers can be added.

In the fourth test case, we can add a single integer 4. The arithmetic mean becomes 2+42 which is equal to 1.


Solution is here:

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,n,j,sum=0;
  6. int a[100];
  7. cin>>t;
  8. while(t--){
  9. cin>>n;
  10. for( j=0;j<n;j++)
  11. {
  12. cin>>a[j];
  13. sum=sum+a[j];
  14.  
  15. }
  16. if(sum<n )cout<<1<<endl;
  17. else cout<<(sum)-n<<endl;
  18. sum=0;
  19. j=0;
  20.  
  21.  
  22. } return 0;
  23. }

Aptitude test assistant programmer 2018

 #include <stdio.h> #include <stdlib.h> int main() { char str[100]; int i; int space=0;     printf("Enter a string\n")...