DecryptionProblem code: CF01 |
All submissions for this problem are available.
Aliens are planning to attack on Earth. Scientists at ISRO got a breakthrough when they were able to intercept the message being transferred in between aliens, but the problem is that aliens are using a technique for encrypting the message. Codefest team of IT-BHU were able to hack into the systems of aliens and decipher the method, the aliens were using for encryption but a method for decryption has not been found yet. You are required to decrypt the message.
The method used for encryption is explained below:
Consider a string of N alphabets for example encrypt (N=7). The string is treated as if the last character wraps around back to the first. Next consider a set S of N different strings, in which each string is formed by cyclic rotation of the alphabets of the original string. So for the string encrypt, S = {encrypt, ncrypte, crypten, ryptenc, yptencr, ptencry, tencryp}
The next step is to perform a lexicographical sort in decreasing order on the set of above strings. So S becomes {yptencr, tencryp, ryptenc, ptencry, ncrypte, encrypt, crypten}
Now, the encyrpted string of N alphabets is formed taking the last character from the above sorted strings. For given example, the encrypted string is rpcyetn. They also send the position of the first character of the encrypted string so that the message can be decrypted i.e. 5 for the given example.
Input
There is a single integer T<=200 on the first line of input which denotes the number of test cases to follow. Each of the next T lines, contains a string made up of k alphabets (a-z characters only) followed by an integer N, separated by a blankspace. 1<=N<=k<=3000.
Output
Output consists of T lines, each containing the decrypted string.
Example
Input: 3 rpcyetn 5 rathe 5 aabb 2 Output: encrypt earth baba
| Date: | 2010-03-26 |
| Time limit: | 1s |
| Source limit: | 50000 |
| Languages: | C C++ 4.0.0-8 C++ 4.3.2 |
Comments

Fetching successful submissions

The 3rd test case is
The 3rd test case is wrong.
Yes. The output for third
abab
i m not able to submit it
i m not able to submit it says... restricted area
@Saransh: have you registered
i am not able to submit a
i am not able to submit a java solution
@coders_ntu : Only C/CPP
@coders_ntu : Only C/CPP codes are allowed for the contest.
// firstapp.cpp : Defines the
// firstapp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#include <stdlib.h>
char buf[3000];
char buf1[3000];
int posit(char t[], int len, char a){
int i;
for(i = 0; i < len; i++){
if(t[i] == a) return i;
}
//This case shouldn't occur
return -1;
}
char* match(int pos, int len){
char tmp[3000];
int cnt = 0;
int index = 0;
tmp[index++] = buf[pos];
while(cnt++ < len){
pos = posit(buf, len, buf1[pos]);
tmp[index++] = buf[pos];
}
tmp[index - 1] = 0;
return tmp;
}
int cmp(const void* arg1, const void* arg2){
char a = *(char*)arg1;
char b = *(char*)arg2;
return a < b ? 1 : (a == b) ? 0 : -1;
}
int main(){
int n = 0, i, pos, len;
scanf("%dn", &n);
for(i = 0; i < n; i++){
scanf("%s %d", buf, &pos);
len = strlen(buf);
strncpy(buf1, buf, len);
qsort((void*)buf1, len, sizeof(char), cmp);
printf("%sn", match(pos - 1, strlen(buf)));
}
return 0;
}
sorry!
sorry!
Why can't I submit?
Why can't I submit?
FDHDFYTF;R57UTFUTIK8I
FDHDFYTF;R57UTFUTIK8I
@digcon9: Have you registered
@digcon9: Have you registered your team for this contest. If yes, login with the team login credentials
I've registerd at itbhu, but
I've registerd at itbhu, but not at codechef. Is there any solution to such problem?
i have looged in with my team
i have looged in with my team 3fools but on submitting it shows internal error occured.........
@digcon9: No, you can not
@digcon9: No, you can not particiapte in the contest. Registration at codechef was compulsary as mentioned in the rules section of the event at Codefest ans Codechef website.
You can still try out the problems and get to know new things when the solutions are released.
@titan: have you registered
@titan: have you registered your team for this contest i.e. MANTH10 at Codechef? If not, then you can not participate.
yes i have registered my
yes i have registered my teamat codechef
team handle "3fools" disply team name "titan"
kindly look into the problem..........
@titan: Kindly, try
@titan: Kindly, try submitting the code again
forgot my team name... not
forgot my team name... not able to submit.. pls help...
@Cinash: Search your team at
@Cinash: Search your team at http://www.codechef.com/teams/list/MANTH10/
my team name is same as the
my team name is same as the codechef username... where do i login with my team name?
@codefest again the same
@codefest again the same problem persists................it says internal error occured on submitting the solution ........
plzzz help............
when i submit the solution,
when i submit the solution, this error is displayed. "contest_problem_id field is required." ... why so ???
what must i do ???
Current ranking is available
Current ranking is available at http://www.codechef.com/teams/list/MANTH10/
@titan: Does the same problem
@titan: Does the same problem occur when you try to submit codes for other problem also?
@define:Try submitting the code for some other problem. Let me know of the outcome.
yes the same problem exists
yes the same problem exists while submitting the slution of other problems.......................
I hv registered my team at
I hv registered my team at codefest... but i m not able to register it on codechef... plz hekp me..
I hv registered my team at
I hv registered my team at codefest... but i m not able to register it on codechef... plz help me...
"contest_problem_id field
"contest_problem_id field is required." ... the same error display occurs everytime ...
however i see that my solutions were submitted ...:) so as long as it is submitted ... no problemo ...
Those who need
Those who need solution...
#include<iostream>
using namespace std;
void merge_sort(char x[], int end, int start) {
int j = 0;
const int size = start - end + 1;
int mid = 0;
int mrg1 = 0;
int mrg2 = 0;
char executing[3000];
if(end == start)
return;
mid = (end + start) / 2;
merge_sort(x, end, mid);
merge_sort(x, mid + 1, start);
for(j = 0; j < size; j++)
executing[j] = x[end + j];
mrg1 = 0;
mrg2 = mid - end + 1;
for(j = 0; j < size; j++) {
if(mrg2 <= start - end)
if(mrg1 <= mid - end)
if(executing[mrg1] < executing[mrg2])
x[j + end] = executing[mrg2++];
else
x[j + end] = executing[mrg1++];
else
x[j + end] = executing[mrg2++];
else
x[j + end] = executing[mrg1++];
}
}
int main()
{
int t;
cin>>t;
cin.ignore('n',10);
char str[3000],str1[3000],result[3000];
int end,pos;
while(t--)
{
cin.getline(str,3000);
end=cin.gcount();
pos=int(str[end-2]-48)-1;
end-=3;
for(int i=0;i<end;i++){
str1[i]=str[i];
}
merge_sort(str1, 0, end-1);
for(int i=0;i<end;i++){
result[i]=str[pos];
str[pos]='@';
for(int j=0;j<end;j++){
if(str[j]==str1[pos]){
pos=j;
break;
}
}
}
result[end]=' ';
cout<<result<<endl;
}
return 0;
}
which compiler r u using??? y
which compiler r u using??? y is iostream.h giving compilation error?
#include<iostream> using
#include<iostream> using
#include<iostream>
using namespace std;
void merge_sort(char x[], int end, int start) {
int j = 0;
const int size = start - end + 1;
int mid = 0;
int mrg1 = 0;
int mrg2 = 0;
char executing[3000];
if(end == start)
return;
mid = (end + start) / 2;
merge_sort(x, end, mid);
merge_sort(x, mid + 1, start);
for(j = 0; j < size; j++)
executing[j] = x[end + j];
mrg1 = 0;
mrg2 = mid - end + 1;
for(j = 0; j < size; j++) {
if(mrg2 <= start - end)
if(mrg1 <= mid - end)
if(executing[mrg1] < executing[mrg2])
x[j + end] = executing[mrg2++];
else
x[j + end] = executing[mrg1++];
else
x[j + end] = executing[mrg2++];
else
x[j + end] = executing[mrg1++];
}
}
int main()
{
int t;
cin>>t;
cin.ignore('n',10);
char str[3000],str1[3000],result[3000];
int end,pos;
while(t--)
{
cin.getline(str,3000);
end=cin.gcount();
pos=int(str[end-2]-48)-1;
end-=3;
for(int i=0;i<end;i++){
str1[i]=str[i];
}
merge_sort(str1, 0, end-1);
for(int i=0;i<end;i++){
result[i]=str[pos];
str[pos]='@';
for(int j=0;j<end;j++){
if(str[j]==str1[pos]){
pos=j;
break;
}
}
}
result[end]=NULL;
cout<<result<<endl;
}
return 0;
}
Copy and paste the solution
Copy and paste the solution in ur source file...
I logged into my account + I
I logged into my account + I have registerd my team,how to login to my team,how to login from my team account ? Am i need to login in both ?
@nice coder: It was required
@nice coder: It was required for you to register both at Codefest and Codechef to participate in the contest.
@Debanjan: Login on codechef
@Debanjan: Login on codechef website with your team handle and password.
I have registered with the
I have registered with the team name CodersOfPhoenix but I forgot my password,what to do ?
@CodeFest But u must had
@CodeFest But u must had provided the option to register even during the contest is taking place... I hv made the solution but not able to submit it... :-(
@CodeFest i think my solution
@CodeFest i think my solution is correct which i hv provided above...!!!!!!!!
@Debanjan: Logout and when
@Debanjan: Logout and when you try to login use the option of forgot password
@nice coder: Rules for
@nice coder: Rules for registration were clearly mentioned on codechef website. You can still try to solve the problems, this will help you to understand the solutions when they will be released.
why our team is not listed in
why our team is not listed in eligible list? we registered on codefest with same name.
is there no way of submitting
is there no way of submitting the solution ..................................i m constantly getting internal error in system............kindly resolve it
@Musketiri : Eligible team
@Musketiri : Eligible team section shows invalid data. All teams registered on Codechef wenbsite and listed at http://www.codechef.com/teams/list/MANTH10/ are eligible for prizes if they form a team for Manthan at Codefest website with same team members. The team names can be different.
@titan: We are trying to resoolve your issue. Please be patient. We will let you know as soon as the problem is resolved.
is anybody dere ??? i m
is anybody dere ??? i m unable 2 submit a single solution..........seems like a dead end.............constantly giving internal system error why so???
@titan: please check your my
@titan: please check your my submissions page. Can you see your submissions on that page?
#include<iostream> using
void merge_sort(char x[], int end, int start) {for(j = 0; j < size; j++) {{cin.ignore('n',10);{for(int i=0;i<end;i++){for(int i=0;i<end;i++){for(int j=0;j<end;j++){if(str[j]==str1[pos]){on clicking mysubmission page
on clicking mysubmission page it says page not found
what will be d output for
@Sankalp: We can only help to
@Sankalp: We can only help to explain the sample test cases, if required, during the contest.
@titan: Thats a really wierd problem. Codechef guys are currently working on your problem and will let you know as soon as the issue is resolved
hey, i cant submit any
hey, i cant submit any solution. there is no submit button for submission although i am logged in. may be this problem is because my profile name is same as my team name. what should i do now???
titan, what is the name of
titan, what is the name of your team?
I also had (well, probably still have) the same problem of not being able to submit solutions and I think the problem could be because of my team name. I entered '.' symbol as my team name (I was surprised that the system allowed me to do that) and I can't submit code or even open team profile page.