0% found this document useful (0 votes)
181 views4 pages

Spoj Solution AMS

This document provides the solution to the SPOJ problem AMSCO2, which involves deciphering an encoded message using the AMSCO cipher. It includes the C++ code for deciphering any message encoded with the AMSCO cipher. The code works by tracking the letters used in the key and encoding the message characters accordingly, printing out the deciphered text.

Uploaded by

Viraj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
181 views4 pages

Spoj Solution AMS

This document provides the solution to the SPOJ problem AMSCO2, which involves deciphering an encoded message using the AMSCO cipher. It includes the C++ code for deciphering any message encoded with the AMSCO cipher. The code works by tracking the letters used in the key and encoding the message characters accordingly, printing out the deciphered text.

Uploaded by

Viraj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SPOJSOLUTIONS

Hereyouwillfindsolutionsofmanyproblemsonspoj.Ifyouwantsolutionofsomeproblemwhichisnotlistedinblogorhavedoubtregardinganyspojproblem(whichihavesolved)oranypro
[email protected]@gmail.com
Andmyhumblerequesttoyouallthatdon'tcopythecodeonlytrytounderstandthelogicandalgorithmbehindthecode.Ihavestartedthisbecauseifyoutriedashardasyoucanandstill
thenyoucanrefertothis.
YoucanreadmyanswerhowtostartcompetitiveprogrammingCLICKHERE

Friday,March28,2014

AMSCO2DeciphertheAMSCOcipher
Linktothequestion
solutiontospojAMSCO2DeciphertheAMSCOcipher
ClickHere,formoredetailsonAMSCOcipherbutyouwon'tneedit.

#include<stdio.h>
intmain()
{
inti,j,t,k,len_str,len_key,count,index,enc_index;charch,key[100],str[300];
while(scanf("%s%s",key,str)!=EOF)
{
intcount=0;charhold[255][255]={0},result[255][255][2];
len_str=1;
while(str[++len_str]!=0);
len_key=1;
while(key[++len_key]!=0);
i=1;
k=len_str/len_key+1;
while(++i<=k)
{
j=1;
while(++j<=len_key)
result[i][j][0]=result[i][j][1]=0;
}
i=1;
k=len_str;
while(++i<255&&k)
{
j=1;
while(++j<len_key&&k)
{
++count;
if(count&1&&k>=2)
{
hold[i][j]='2';
k=2;
}
else
{
hold[i][j]='1';
k;
}
}
}
enc_index=1;

k=len_key;
while(k)
{
ch='a';
i=1;
while(key[++i]!=0)
if(ch>key[i])
{
index=i;
ch=key[i];
}
i=1;
while(hold[++i][index])
{
result[i][index][0]=str[++enc_index];
if(hold[i][index]=='2')
{
result[i][index][1]=str[++enc_index];
}
}
key[index]='a';
}
i=1;
k=len_str;
while(++i<255&&k)
{
j=1;
while(++j<len_key&&k)
{
printf("%c",result[i][j][0]);
k;
if(result[i][j][1])
{
printf("%c",result[i][j][1]);
k;
}
}
}
printf("\n");
}
return0;
}

PostedbyLackofProperNameat3:22PM
EmailThisBlogThis!SharetoTwitterSharetoFacebookSharetoPinterest

NewerPostOlderPostHome
Subscribeto:PostComments(Atom)

SearchThisBlog
Loading...

ALLPOST
2015(34)
October(9)
September(5)
August(5)
June(1)
February(6)
January(8)
2014(143)
December(6)
November(9)
October(15)
September(1)
August(9)
July(5)
June(10)
May(11)
April(7)
March(31)

SIRNUMSSIRCHIRAGANDMAGIC
NUMBERS
BLOPEROperators
RMIDRunningMedianRevisited
AMSCO1TheAMSCOcipher
AMSCO2DeciphertheAMSCOcipher
ICPC12CTheEncryptedPassword
FERT21_0Matches
RMIDRunningMedian
GSSQUNCESequence
IITWPC4DArrangementValidity
binaryindexedtreeBIT
JOKER1KnifesAreFun
QN01XORGame
IITKWPCOCreateCollections
LOOPEXPLoopExpectation
SPCJGopuandCreateCollectionsPartTwo
BOGGLEBoggleScoring
IITWPC4CMagguandVectors
AKVOD05RossgeneratesData
GOPI_SWGopiandSandwich
MSCHEDMilkScheduling
GSHOPRamaandFriends
BTCD14AGameofPips
LKSLargeKnapsack
HLP_RAMSTopperRamaRao
EMTY2CanYouMakeItEmpty
TRIGALGEEasyCalculation
SNGMSGEncodeMessage
SYNC13CWHATACOACCIDENT
PRISMSATRIANGULARPRISM
TipTopGameTIPTOP
February(30)
January(9)
2013(34)
December(34)

FacebookFollowers

Subscribe

Posts

Comments

pagehits

Therewasanerrorinthisgadget

FollowbyEmail
Emailaddress...

Submit

Google+Followers

Contributors
NishantRaj
NishantRaj

Labels
math(27)implementation(23)Graph(12)
BinarySearch(11)prime(11)Dynamic
Programming(10)BFS(8)BIT(7)Strings
(7)easy(7)primefactorization(7)DFS(6)
greedy(6)Hash(5)SegmentTree(5)Suffix
Array(4)AVLTree(2)ConvexHull(2)Game
Theory(2)HeightBalancedTree(2)Z
function(2)factorization(2)fibonacci(2)
matrixexponentiation(2)sorting(2)2DBIT
(1)BipartiteGraph(1)Editdistance(1)
GrundyNumbers(1)Heap(1)LCP(1)
LinkedListdatastructure(1)PolicyBased
DataStructure(1)PriorityQueue(1)Rolling
Hash(1)TriesDatastructure(1)contest(1)
floydwarshall(1)inversemodulo(1)
moderate(1)offlinequery(1)queue(1)
sieve(1)stack(1)stringmatching(1)
tetranacci(1)tree(1)twopointer(1)

PopularPosts

AGGRCOWAggressivecows
BelowgivencodeisforAGGRCOWspojAggressivecowsspoj.Hint:ThinkBinarysearch,#include<bits/stdc++.h>usingnamesp...
PPATHPrimePath
PrimePathBelowgivencodeisforPPATHspojorPrimepathspoj.Hint:UseBFSandsieve.#include<bits/stdc++.h>us...
PT07ZLongestpathinatree
LongestpathinatreeGivenbelowcodeisforPTZ07ZspojorLongestpathinatreespoj.YoucansolvethisusingDFSofapplyi...
PALINTheNextPalindrome
Google+BadgeItisasolutiontothe5thandoneofmostattractiveproblemtonovice,aswellasexperiencedhackeriftheyhaven'tdonewithit...
SegmenttreeGSS3&GSS1
Firstofallreadaboutsegmenttreeanditbasicfunctioning.YoucanreaditfromHERE.GivenbelowcodeisforGSS3&GSS1spoj...

Myotherblogs

RealThrills

NISHNATRAJ.PoweredbyBlogger.

You might also like