Saturday, July 25, 2020

80A - Panoramix's Prediction

80A - Panoramix's Prediction

#include<iostream>
using namespace std;
int primechecker(int n){
 int i;
 bool f =true;
 for(int i=2;i<n ;i++)
    if(n%i==0) {  f = false;  }
   if(f) return 1;
   else return 0;

    }
int main()
  {
   int n,m,result;
   cin>>n>>m;
    for(int i=0;i<50;i++){
   n++;
   if(primechecker(n)==1) { result = n; break;}

   }
   if(result==m) cout<<"YES";
   else cout<<"NO";
   }


Tuesday, July 21, 2020

104A - Blackjack

104A - Blackjack

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n;
  5. cin>>n;
  6. int d=n-10;
  7. if(d==10 ) cout<<15;
  8. else if(d==0) cout<<0;
  9. else if(d>11 or n<=10) cout<<0;
  10. else if(d<=11)cout<<4;
  11. }

609A - A. USB Flash Drives

609A - USB Flash Drives

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n,m;
  5. cin>>n>>m;
  6. int a[n];
  7. for(int i=0;i<n;i++) cin>>a[i];
  8. sort(a,a+n);
  9. reverse(a,a+n);
  10. int s=0;
  11. int i=0,ans=0;
  12. while(1){
  13. s=s+a[i];
  14.  
  15. ans++;i++;if(s>=m) break;
  16. }cout<<ans;
  17. }

Monday, July 20, 2020

870A - Search for Pretty Integers

  1. link 870A - Search for Pretty Integers
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. int main(){
  5. int n,m;
  6. cin>>n>>m;
  7. int a[n],b[m];
  8. for(int i =0;i<n;i++) cin>>a[i];
  9. for(int i =0;i<m;i++) cin>>b[i];
  10. int ans=999999;
  11. for(int i=0;i<n;i++){
  12. for(int j=0;j<m;j++){
  13. if(a[i]== b[j]){
  14. ans = min(ans, a[i] );
  15. }
  16. else {
  17. ans = min(ans,10*a[i]+b[j]);
  18. ans = min(ans,10*b[j]+a[i]);
  19. }
  20.  
  21. }
  22.  
  23. } cout<<ans;
  24.  
  25. }

Sunday, July 19, 2020

898A - Rounding

                                                                898A - Rounding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded.

For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ways are correct.

For given n find out to which integer will Vasya round it.

Input

The first line contains single integer n (0 ≤ n ≤ 109) — number that Vasya has.

Output

Print result of rounding n. Pay attention that in some cases answer isn't unique. In that case print any correct answer.

Examples
input
Copy
5
output
Copy
0
input
Copy
113
output
Copy
110
input
Copy
1000000000
output
Copy
1000000000
input
Copy
5432359
output
Copy
5432360
Note

In the first example n = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.


  1. #include<iostream>
  2. using namespace std;
  3. int f(long n){
  4. int i;
  5. while(n>0){
  6. n = n%10;
  7. return n;
  8.  
  9.  
  10. }
  11. }
  12. int main(){
  13. long n,in,dec;
  14. cin>>n;
  15. in = n;
  16. dec = in;
  17. long x,y;
  18. long a =0,b=0;
  19. while(1){
  20. if(f(in)==0 ) { x=in;break;}
  21. in++;
  22. a++;
  23. }
  24. while(1){
  25. if(f(dec)==0 or dec==0 ) { y=dec;break;}
  26. dec--;
  27. b++;
  28. }
  29. if(a<b) cout<<n+a;
  30. else cout<<n-b;
  31.  
  32.  
  33. return 0;
  34. }





















Friday, July 17, 2020

805A - Fake NP

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it's not a NP problem.
Input
The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).
Output
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
Examples
input
Copy
19 29
output
Copy
2
input
Copy
3 6
output
Copy
3
Note
The first example: from 19 to 29 these numbers are divisible by 2{20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3{3, 6}.







  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. long int l,r;
  5. cin>>l>>r;
  6.  
  7. int d=abs(l-r);
  8. if(d>0) cout<<2;
  9. else if(d==0){cout<<l; }
  10. return 0;
  11. }
  12.  







                                                           798A - . Mike and palindrome
             memory limit per test
256 megabytes
input
standard input
output
standard output
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.

 Solution:
                                                            A. Mike and palindrome
             memory limit per test
256 megabytes
input
standard input
output
standard output
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
input
Copy
abccaa
output
Copy
YES
input
Copy
abbcca
output
Copy
NO
input
Copy
abcda
output
Copy
YES


 #include<bits/stdc++.h>
using namespace std;
int main(){

  string s;
  cin>>s;
int ans=0;
  int d=s.length()/2  ;
  //s.reverse( );
 int i=0;
 while(d-- )
{
  if(s[i]!=s[s.length()-1-i])
  ans++;
  i++;

}if(ans==0 and s.length()%2==1) cout<<"YES";
else if(ans==1  ) cout<<"YES";
else cout<<"NO";
 //cout<<ans;
}

798A - Mike and palindrome

                                                           798A - . Mike and palindrome
             memory limit per test
256 megabytes
input
standard input
output
standard output

Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.

A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.

Input

The first and single line contains string s (1 ≤ |s| ≤ 15).

Output

Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.


 Solution:
                                                            A. Mike and palindrome
             memory limit per test
256 megabytes
input
standard input
output
standard output

Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.

A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.

Input

The first and single line contains string s (1 ≤ |s| ≤ 15).

Output

Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.

Examples
input
Copy
abccaa
output
Copy
YES
input
Copy
abbcca
output
Copy
NO
input
Copy
abcda
output
Copy
YES



 #include<bits/stdc++.h>
using namespace std;
int main(){

  string s;
  cin>>s;
int ans=0;
  int d=s.length()/2  ;
  //s.reverse( );
 int i=0;
 while(d-- )
{
  if(s[i]!=s[s.length()-1-i])
  ans++;
  i++;

}if(ans==0 and s.length()%2==1) cout<<"YES";
else if(ans==1  ) cout<<"YES";
else cout<<"NO";
 //cout<<ans;
}

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")...