Saturday, July 25, 2020
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
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int n;
- cin>>n;
- int d=n-10;
- if(d==10 ) cout<<15;
- else if(d==0) cout<<0;
- else if(d>11 or n<=10) cout<<0;
- else if(d<=11)cout<<4;
- }
609A - A. USB Flash Drives
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int n,m;
- cin>>n>>m;
- int a[n];
- for(int i=0;i<n;i++) cin>>a[i];
- sort(a,a+n);
- reverse(a,a+n);
- int s=0;
- int i=0,ans=0;
- while(1){
- s=s+a[i];
- ans++;i++;if(s>=m) break;
- }cout<<ans;
- }
Monday, July 20, 2020
870A - Search for Pretty Integers
- link 870A - Search for Pretty Integers
-
-
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int n,m;
- cin>>n>>m;
- int a[n],b[m];
- for(int i =0;i<n;i++) cin>>a[i];
- for(int i =0;i<m;i++) cin>>b[i];
- int ans=999999;
- for(int i=0;i<n;i++){
- for(int j=0;j<m;j++){
- if(a[i]== b[j]){
- ans = min(ans, a[i] );
- }
- else {
- ans = min(ans,10*a[i]+b[j]);
- ans = min(ans,10*b[j]+a[i]);
- }
-
- }
-
- } cout<<ans;
-
- }
Sunday, July 19, 2020
898A - Rounding
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.
The first line contains single integer n (0 ≤ n ≤ 109) — number that Vasya has.
Print result of rounding n. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
5
0
113
110
1000000000
1000000000
5432359
5432360
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.
- #include<iostream>
- using namespace std;
- int f(long n){
- int i;
- while(n>0){
- n = n%10;
- return n;
- }
- }
- int main(){
- long n,in,dec;
- cin>>n;
- in = n;
- dec = in;
- long x,y;
- long a =0,b=0;
- while(1){
- if(f(in)==0 ) { x=in;break;}
- in++;
- a++;
- }
- while(1){
- if(f(dec)==0 or dec==0 ) { y=dec;break;}
- dec--;
- b++;
- }
- if(a<b) cout<<n+a;
- else cout<<n-b;
- return 0;
- }
Friday, July 17, 2020
805A - Fake NP
19 29
2
3 6
3
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- long int l,r;
- cin>>l>>r;
-
- int d=abs(l-r);
- if(d>0) cout<<2;
- else if(d==0){cout<<l; }
- return 0;
- }
-
Solution:
abccaa
YES
abbcca
NO
abcda
YES
798A - Mike and palindrome
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.
The first and single line contains string s (1 ≤ |s| ≤ 15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Solution:
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.
The first and single line contains string s (1 ≤ |s| ≤ 15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
abccaa
YES
abbcca
NO
abcda
YES
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")...
-
104A - Blackjack #include < bits / stdc ++. h > using namespace std ; int main (){ int n ; cin >> n ; int d = n - 10 ; ...
-
A. YES or YES? There is a string s � of length 3 3 , consisting of uppercase and lowercase English letters. Check if it is equal to &qu...
-
#include <iostream> using namespace std ; int main () { int n ; int q = 2 ; int c = 0 ; cin >> n ; if ( n % 2 == ...