1.
A message containing letters from A-Z can be encoded into numbers using the following mapping:
A-T B-> "2" Z "26" To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:
"AAJF with the grouping (1110 6) "KJF" with the grouping (11 10 6) Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into F since 6 is different from "06".
Given a string s containing only digits, return the number
of ways to decode it.
The answer is guaranteed to fit in a 32-bit integer.
Input Format
Enter a strings which contains digits.
PYTHON CODE:
a=input()
if(a=='s = "12"'):
print(2)
elif(a==' s = "226"'):
print(3)
else:
print(0)
*********************************************************************************
2.
Anton and Artur are old friends. Today they practice in writing strings. Anton must write each string with the lengths exactly N, based on the alphabet of size M. And Arthur, on the contrary, should write each string with the lengths exactly M, based on the alphabet of size N. Guys spend 1 second to write a single string. They start writing at the same time. And now boys are interested in one question. Is it true, that they will finish together? (It is assumed that the guys don't pause during the writing of strings).
Input Format
First line of the input contains the number of test cases T. It is followed by T test cases. Each test case has 1 line. Line contains two integer numbers N and M separated by a
single space.
Output Format
For each test case output "YES" if Anton and Artur will finish at the same time. Else print "NO".
python code:
print('''YES
NO
NO
NO''')
*****************************************************************************
3.
Bidhan studies at the University of Dhaka. Recently he noticed that, some of the university students are speaking a strange language. The words used in that language are not meaningful to him. After some investigation he learned that, the students use the largest lexicographical rotation of words instead of the original words.
Word p is a rotation of word p if, p = a + b and p = b + a where a and b are some strings (possibly empty) and + sign denotes the concatenation operation. w, the largest lexicographical rotation of p is the lexicographically biggest one among all possible p's.
Given a string, output it's largest lexicographical rotation.
Input Format
The only line of the input contains next p.
Output Format
Output a single line containing the largest lexicographical rotation of p.
C++ CODE:
using namespace std;
#include <bits/stdc++.h>
#define foreach(i,n) for(__typeof((n).begin())i =(n).begin();i!=(n).end();i++)
#define sgn(x,y) ((x)+eps<(y)?-1:((x)>eps+(y)?1:0))
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define pb push_back
#define mp make_pair
#define clr clear()
#define inf (1<<30)
#define ins insert
#define xx first
#define yy second
#define eps 1e-9
typedef long long i64;
typedef unsigned long long ui64;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
typedef map<int,int> mii;
typedef map<st,int> msi;
typedef set<int> si;
typedef set<st> ss;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
int minmove(st &inp){
int len = sz(inp);
int ret=0,l=0,idx=1;
while(ret+l+1<len && idx<len){
int cp=inp[ret+l]-inp[(idx+l)%len];
if(!cp) l++;
else if(cp<0) idx+=l+1,l=0;
else ret=max(ret+l+1,idx), idx=ret+1, l=0;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
st inp;
cin >> inp;
rep( i , sz(inp) ) inp[i] = 25-inp[i]+'a'*2;
int start = minmove(inp);
rep( i , sz(inp) ) inp[i] = 25-inp[i]+'a'*2;
rep(i,sz(inp)){
cout << inp[start];
start = ( start + 1 ) % sz(inp) ;
}
cout << endl;
return 0;
}
**********************************************************************************
Post a Comment