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...
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 ;}
262A - Roma and Lucky Numbers #include < bits / stdc ++. h > using namespace std ; int main () { int n , k , c = 0 , ans = 0 ; cin >> n >> k ; while ( n --) { c = 0 ; string s ; cin >> s ; for ( int i = 0 ; i < s . length (); i ++){ if ( s [ i ]== '4' or s [ i ]== '7' ) c ++; } if ( c <= k ) ans ++; } cout << ans ; return 0 ; }
Comments
Post a Comment