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 " (wi...
#include <iostream> #include <algorithm> using namespace std ; int main () { long int n ; cin >> n ; long long arr [ n ]; for ( int j = 0 ; j < n ; j ++){ cin >> arr [ j ];} sort ( arr , arr + n ); int b = arr [ 0 ]; int l = arr [ n - 1 ]; int x = 0 ; for ( int i = b ; i <= l ; i ++) { x ++; } cout << x - n ; return 0 ; }
Problem link Solution O(1) #include <stdio.h> #include <iostream> using namespace std ; int main () { long int l , r ; int t ; cin >> t ; long int x = l , y = r ; while ( t --) { scanf ( "%ld" ,& l ); scanf ( "%ld" ,& r ); y = r ; int mod =( r % l ); cout << l << " " << r - mod << endl ; mod = 0 ; } return 0 ;}
Comments
Post a Comment