## 306 - Cipher

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 306 Cipher (WA)

You need to find a cycle for each position, k may be large.
Check input and AC output for thousands of problems on uDebug!

hoimo
New poster
Posts: 18
Joined: Sun Sep 23, 2012 3:43 am

### Re: 306 Cipher (WA)

Thanx 4 reply.
I've changed my code as below but now its RUNTIME ERROR.

Code: Select all

``````#include<stdio.h>
#include<string.h>

int main()
{
int inp[202], n, i, j, k, range, cnt, len;
char str[202], rep[202];
int store[202][1000], pnt;

for( i=0; i<203; i++ )
store[0][i]=i;

while(scanf("%d", &n) == 1)
{
if( n==0 )
break;

for( i=1; i<=n; i++ )
scanf("%d",&inp[i]);

cnt=0;
for( i=1; cnt<n; i++ )
{
cnt=0;
for( j=1; j<=n; j++ )
store[i][inp[j]] = store[i-1][j];

for( j=1; j<=n; j++ )
{
if( store[i][j] == j )
cnt++;
else
break;
}
}
if( i>1 )
range = i-1;
else
range = 1;

while( scanf("%d",&k) == 1 )
{
if( k!=0 )
{
getchar();
gets(str);

if( k>range )
pnt = k%range;
else
pnt = k;

len = strlen(str);

if( len != n )
{
for( i=len; i<=n; i++ )
str[i] = ' ';
str[i] = '\0';
}

for( i=0; i<n; i++ )
rep[i] = str[store[pnt][i+1]-1];

rep[i]='\0';
puts(rep);

}
else
break;
}
printf("\n");
}
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 306 Cipher (WA)

Input:

Code: Select all

``````5
1 2 3 5 4
901872 KPZQW
563199 UoxtS
543573 aUVek
0
140
14 3 53 134 114 13 91 117 67 90 19 71 128 106 94 112 135 76 105 44 7 113 51 77 48 120 26 125 115 72 35 98 25 52 12 31 108 4 47 58 63 61 93 2 110 107 68 27 6 119 89 97 70 39 69 118 127 121 126 32 109 42 54 5 140 24 100 129 116 92 74 102 104 60 41 78 33 49 88 36 138 124 136 99 1 57 50 82 75 17 101 40 18 86 80 66 21 139 34 28 37 10 87 132 43 23 11 103 8 29 131 123 30 73 96 15 9 62 122 85 16 137 55 83 46 130 59 65 79 22 64 95 38 45 56 20 111 133 81 84
880692 zBSwEguYtwVbSMfwwuvgLILgPyQwgRsumGglbZftnKtsSpXAzvucCJlfWgzUJDZsNiugOGVahkiATyLtIiqbHHYXRMptRdmDDBgBNsStANvACtfnOgTJsVvzyNXKuRCkwMzaAFotWHwW
206299 qCEvfWnfXAyBWeVQrkNUuAiVlKktLawUlnmvaRcOKYPdskwGNIDjzPOSGWKXhvQNZgBiPgdFRfcjoQKMDniitgPiQmRgepEZuPKhQEcpbOZDtVviLXzFtYYrPZcyyXsNjdsBUKNzjXcl
473947 LKlGVQScQHYcjCfzBndolElZhVUFRMLpYdXczpQMZEIaqBbsVgqEtZNjWKzHbvAimqZtvdiyeLvuECEdBuSWkxqyiZeDlqVmQBYyzaYmlKGCxnnrjRRSpLVujYvLvncQAvZnjCvLEYOU
420577 KokRXsAxlVqRbrpYUppztADtCbvxMLPCyTCdPtFKGBfAPVWStkhwTqehnollbHgSMXTrLNlchsGUogCxELqLprXanYbEwlLQGohaCYoDUawnQvMvpsovNQWgzQoRhLaPSpeZIvMYMixh
455433 UOQXxDFtUKaLgoxzTXxkcHNHcgqvIJfzbltWoFfOeoOvxeQFcSosUJMlUpmJQoUxJvignERSSyROapxxgiGsjvPQwOzWIZclpYntPaeQgQIkevgQgVhtfekNAcWCXJidqMMvzgYHALwC
0
88
73 45 85 62 83 32 7 60 2 20 53 80 29 63 24 4 36 88 26 8 23 57 16 42 72 51 68 41 22 43 78 30 79 28 69 65 70 87 14 18 82 46 11 21 56 48 9 1 76 5 27 71 17 75 10 31 66 25 74 13 6 59 15 61 54 3 50 39 67 64 47 40 37 35 86 58 33 84 19 77 12 38 34 44 55 49 52 81
147922 fcwsRedKIJzqpmJzCqeLZdTKGJHxfeLDHOEMUietnSDvzZdcxBVhCgJtEVCqRrTloWAbWNjDXWuFfjutJXWpkZoI
844710 HZsBYnWBwLEiEZoQzqElxXbJnXCdkppvyiHhvaEWFMaqSLnAusEKfAtDTKhfiLZLWbgDWyFvVtGgrnfOFFDaQwEW
402035 qGkiKmRqVmiAmNVDtEgknbNpAuRRTkWDZuuYEqUGGDWEeiFPTLSwnUREeahRWnnjrVHkiEhBSLKqGMLBrOqvHbia
729845 nswbppaeJQaqSmhewPdzqejrPdyuboWEVsNqJyHMxRORVZCobwBUOHkUMiAThPZjoRXEiIGeSYMQLflNwSRiJVYn
937051 LbcPBuMqoKwWHpcTvRqhHkbOoEmErAEKPZjzNoOhDrplUdGBoDksqqlKlHclGyCMCuvMTvdvktBMwxLTcccNVcRR
57817 KHfNpChDUaTibVzjtdIRFanOjynIQwFeZWCILypmeFSktepxUzlgtyukYrddMySstiaEudROfiMiucEAPFZmNmGY
845260 IVFraSGMWRPuBmbLvGEpDdAbsDJRCPDQjCWVanPYLSCINmAtBBQdxShWTqaDXiSmBXokrdXtSOLIjLYZOUxtlrza
512871 RjxrJsWZnvZHCYrnhTxzHrkBwVkwtDrtrfzuXOfJoajnvnJmvqyfAHlhZaIMgRLrVdtUDZwTTHLGVkBpkWeBwyMR
392424 YCNPHoowLOezWskhHcGHSXMTyCelvsGQijPdqtxdwdkFWpzRCaWeITnfemZYRaVbWwhHzwyYMVGLJrGIwVeWEUzK
180484 HOKMfddYeoCNpacTNMvyVcmfGYPmDSbtTrISufxYISKfuXmNayvNpagtznVCTMUmheFvNKUITfQFLQUBTfAUygkQ
0
117
112 20 61 84 107 110 26 79 73 116 31 5 22 106 50 91 56 11 12 101 42 81 30 86 37 96 15 94 98 59 40 114 9 6 3 38 102 75 13 78 55 97 64 41 111 100 76 46 70 34 103 48 109 87 36 89 51 82 52 58 95 49 32 105 117 10 62 63 77 93 25 45 24 43 53 88 44 65 4 2 33 80 35 21 104 18 83 47 16 108 60 85 90 71 57 92 74 14 17 27 67 7 39 8 19 72 66 68 1 23 113 29 54 99 115 69 28
887405 YFNsyNquDKIQLzYeaNXXbZCpCBUOQVinOXkgGHCRaSnAxWappZIpPBwaoRaJScTiHOQICbExuyMuqasWrrQpkvwjKOofhSOcDQWQAvfQlOpiazTYzSwcv
682013 cmqIjDgIbxltKlBEpXmboFkwAMHTnzPTZmDKUqfUISsJsxSRMFVIJzpWfPeFklvWHaXvMWrbnXssJlFQmVDRoTmHorLoPaiNJiceSztEORKThYMOUkzOP
177868 KDoMNlCmtKUFIJMzarHgYKYZZOTQoddYIWuPxABqKXaHsTscjwGDLaEoawEtRVJnAaVkkxFFBIGFsIAwhgekFdvsnGFumzBoukPoEGdyanPELRDXeZFPH
139674 mJWugirdReprtzlrqHRrfKQDAZxbwxxKTeukwzmvqGOgKUvyZdZWMlbOehEgUXJIYFCwYQRVdRrZdewxbwfWCHwRgLkMlCHdGQUtctgbxLBxPxcjEyQaT
813777 zWdyNJoCNYNVspjhQXPIWKCYwQzACgBysPXqRHSmfbQAuLTRJWEFsqtaHGgwMXTwWnkygOvbtFsZloPLgqvUgFaJSSTsrLtUwTCVxQiSrqdQSgzpPPycM
876212 XqmqgOslTUCjDYKZQhTAXGLwhAZhigBbyWJvSAxlQRATHfIeREEjEBjLEseRPxgKhCrjzBCkSptjfKKNLGFBdqrOHhmLXFqdJHzymmUrIcPoLWNhkRAQh
315914 CmQkdALnkYbcreBBQldtYXRBDmQRLpgUHdfSuQfoTPuUFvDJzznOmUwbpDyqlQFeNpXJHcqYWRFZVIqJrGBCXRNSWgTvYtTwdFvqRharlcHzeYxMAidsj
0
161
86 90 142 161 51 59 119 40 2 47 83 151 16 118 39 159 25 148 111 87 63 125 17 155 103 34 128 129 44 29 11 38 52 133 130 127 141 41 10 102 92 93 22 96 60 46 156 97 35 1 150 108 94 80 89 122 62 149 144 104 56 65 70 58 117 77 37 28 131 158 110 71 91 64 112 15 136 123 146 3 61 82 14 121 154 114 124 27 7 99 48 160 36 75 19 33 20 98 81 135 24 53 12 78 138 50 13 132 113 55 67 42 115 101 137 126 84 18 9 79 109 134 74 100 30 66 23 76 88 68 152 45 21 157 143 6 49 145 95 69 72 4 140 54 43 73 116 147 139 26 153 85 57 32 107 120 31 8 106 105 5
211420 PTYoYlKPnXLhzhZdMzcrhUtbaXhtexhuzgMGDOPDPClhawheomIVyKbEtsGWiRPZfEHDLUdigFDUACiSsFyGxYybkrMbabMaQdRzlTKPDNwDwhYoQGEYJaorzJUWtBplLnBhfGCNBaQPdfkakQDzjGFQUfqWQNrBE
580029 jseAFiSvRaIBVoXTBBNbWjmTYrzvKWSQCDuKRJzIAHtTNPHDzDOMiIajtzvuMQQIBLAwxwYAzfYfMHqWDklqmiTBlPkwRDzCnjShOQYCcxOkcpsHgETHcTTORhiOInxhMHaRqgjFIjJDcvmiSiHxNkYbeAjgWQilR
944695 yuJkxLgghEiNSfgQxhkSupEYJLpLqdQFIwhZudnmLqXJvOJBILNsdIcRTRmIqXsvxstYKsDFtSyrzSOTVBaqjdtnHYIWfYDiHRLxrJnbCzQTLskPoCqWCWdJDtgtfiQlggqjlmKYIJGJTHRQlZcXSbHQVGEQlhTfx
0
94
74 9 17 36 28 72 46 86 2 32 35 20 10 18 13 22 53 40 12 82 31 34 79 90 80 23 19 54 73 21 3 76 38 57 49 25 56 91 14 7 68 37 29 94 70 43 41 67 30 65 75 42 84 78 4 59 85 11 83 88 63 61 52 55 6 81 26 1 64 39 93 27 47 48 66 51 92 45 24 16 60 44 77 89 71 5 15 62 69 58 87 8 33 50
653263 zEAWGyueJuIrEwMulTpOJGxzLVgopgnsCldrRtkWQrEJRZShFqxzhEpPwdpxEpSUSKVhFwPBVpTSoxhGfqFekJnptUTOvq
0
179
5 115 166 99 65 86 148 172 14 74 171 4 124 37 170 44 60 130 54 97 127 63 133 77 81 34 38 92 67 96 8 150 43 138 154 53 12 11 2 139 42 159 36 31 112 105 108 32 61 1 20 135 49 104 22 23 102 123 68 88 116 26 167 21 110 98 120 7 134 16 119 87 40 79 160 29 168 165 50 70 151 132 122 152 153 94 143 66 161 131 177 106 35 10 48 27 140 57 80 147 169 90 24 156 78 111 142 149 51 107 126 144 18 56 19 85 146 129 73 58 113 174 41 101 17 3 83 179 6 162 89 155 118 121 47 145 93 141 84 69 176 109 82 46 25 136 45 173 33 9 39 128 76 30 157 163 91 55 71 175 64 15 103 13 52 178 72 114 95 137 158 100 59 75 28 125 117 62 164
39981 bGWjHzfNedsMmZLsvHfhWNfUEVJQWPLxjcYcUzslVVqcBxeZCFoZBLxsFbbMbvkVXqNzqKimTQxCQFuQfjxhUHXvNnRjrLTgltaCvaHkkHrljvbcWzZrPOQtdeVhqIigKBkgozzjXbgwkQszfOxRuvlaVajceruBVtpHdhjwlMWtlyCJsRp
0
64
61 9 63 5 14 15 58 28 7 8 47 45 19 2 4 56 23 39 48 24 30 51 3 32 13 37 29 64 41 62 12 25 31 6 33 54 59 50 35 10 27 17 38 40 34 36 22 57 44 60 21 52 18 20 26 49 42 46 11 1 55 16 43 53
13809 JykABxFxfFWBaGdbXETmwWPcTGUIduMXYTKpTKiFXvXpUlgsLzugdBeqUUPVutOk
286011 lVIEOfHSDkHIqgwEMiqvHDKklgTJDrbJzkIwKHZnReMxHsNwvgPwGXyTHbpkpgfT
48791 ZchnzMOUggcylMXCaDgVNWmsJCdsfgvDOcBfIrtqlovhMGbEvnhNvnSTZyPWYKrq
673115 dFbujcdpkDiPuggGLkjwQknKmqAMxFtqbSIjsYYedIbytfSSzIbLocxacDjdiqfx
329127 IyDQymgjrBQhVGjAeTTWrAYRVPyoiZIkBVQQfIZVwKkrwLUTAsMbBVnAgINJWosN
351250 IPPuFPZgLZgLXWQmETjuPPMbsPkEdSvwITJJzQUpvPgPAhQwWrhhCvUNrwCJxBVn
991651 exJkDeYhRFtENhGedujypExsVxJaWkkQsdTqHyjwrvBygeYHhvPnICfaYysagqZX
933778 ScaOcuiDOxFSPlwBHxDZvLmKVniKHNruRkddGghVCfViMFmGtcGzWjxLrkgqrAyJ
47429 ljRrEVKeFGLSdJHnvmUkEncPPkAMBsyCghWfzRoLDiaLplOjEzmCYPbWznyfIgGt
0
95
60 95 85 82 63 29 75 81 89 37 3 50 86 34 53 49 94 14 39 24 20 65 35 5 41 56 13 23 61 16 77 92 78 26 18 25 71 54 30 12 55 40 69 67 87 64 7 66 79 21 4 10 51 47 45 33 27 28 11 2 93 9 74 44 88 31 19 91 52 57 38 1 76 58 15 73 42 80 72 32 46 6 43 70 8 36 62 59 90 22 84 48 83 17 68
530720 zpQdPTqMzJPQWyADGhGGWUQAjlFPCPTGozBUimXqBggkLpwhmHPoTYsZvBEOPYBYSCKJuwahczYZRyhIfIfVCppAjBPuaBT
332381 YpDnlUyQdtheWrumBkMLIpBXxpoWXTTNlBzZxPVeHaTjolJdzuXkJtOavuZhjyTpJxEBiTWXVJyNLboBbGJUFSKwifyPHSJ
0
135
85 129 39 113 126 106 111 21 36 99 114 59 71 16 83 7 46 128 45 47 57 10 105 86 12 14 103 120 41 35 32 101 89 54 77 29 96 81 18 117 53 112 17 25 13 44 43 93 23 122 65 24 40 133 121 108 75 22 27 6 66 5 72 58 98 49 131 62 107 15 80 11 20 63 135 124 130 125 60 132 2 87 95 116 102 118 91 33 74 100 68 8 51 69 1 37 79 3 82 34 64 70 19 76 104 26 84 52 97 38 9 123 42 30 50 4 110 119 28 67 90 92 31 109 48 127 134 94 55 61 73 88 78 56 115
830992 IMJCPhmWYFfJzJiwzggQXwufRBHevLwWugmYzVOQSEEiZFHufEadyvFWfBNlGjwsgVzJdosKMiwonSgnJvlhNZHewyiWOhdjfUnhbJTHBjvjxgPpAPPRhCPssEiZiJzUMOKujtL
721856 DZZqyUaTGqPGJCqchNTPGrehRWZqKrnaABVNclstUTWdgNUoDoIDjTipgxunbWnqdqJzjzJUzVyYkvGSTxgyTiovyJBYDPiVtHTrHQGlDdguZvrnPoGWhNztZjDsOoiUdHSBroS
469387 sdnsXGpbpVgEtXogRkwWKCPQTGqIIvOHQjwhLhRfPMzQCgQVivMKqATsvpaetsBTwoviwvPcvjAYZhilRrEcjsPPrJNocOWVbGnhibzlqLDrVxgLFqctcMKvtFhHdZwXGyNULUG
654784 CEjifpKnJMSoOGfKziqYENTfIuwmJzVyzFBMVwGsurYEAYoSGEePUrnPyCngkjEOcULKvfovGnekCQzWbmCRdJxHEzTChgbjvOVwHrlMVbZoyOZdXtASYQmDraiymHoJfGvQoho
717636 gnAxSRZRKVTklXJBepupaTooIQhtUIEubPylOatDAEvDTVAiZzFYsAPPACVoXObzVaMxZtejEBxqbtCFUbioAculdzGuxMJYDNCxokQImubCGAKWCboMCnuogDAIYYKaIXEeIBN
0
0
``````
AC output:

Code: Select all

``````KPZQW
UoxSt
aUVke

sAtnfSQmlNugtwGSfABVAAwWROIbJYqCzTtKHwCyDhIvlkYMFLomRJWsLzpStgKJTHssbusvgBVZCwuitwpiaDNBfWyAHcXdPGggzvMwwMUzaOnkSXfgtEuRgRNuVNugtbZLyXzvigtD
XKnAErPXRwZOtBZaBlglQptNvthsEEipYQcQidPnyPoiaLeYKnycjbPfsRfVcUNCervkIuPMgFZGSkQPsWNitviNkmculjWmKgDKwvKgVhzjDFUDBzAYUXyfQicWVXNqjRdOXLdZzKGO
YHpVvzztEKavrqmGqDKicVVdlzeLmkydQqFZECRYZZtLjLeSjaYxBVnvEjhYQAiLNYymROBLbGnMEKVQlcXSCZydElnBdqpWWlfuvCMxlgojbQvCuEURAZHzpZqLSsYvnUjcuQicBnIv
RnGZwNfLAoUklvYSLBMDUKvsoiEcPzoMCwXnUDyFXnQhxVCxxbMqGoLpoWTMartTalpSRgWYtQQblQbPXprhtAsgoewqHzCRpeVLpvtAhPYgldLCoGCqplPIrMaKYNkTvEhbhLvahsSx
IJffzvpJaxogXhQCvfoeOQvwzgXTyMcVLOAkgWgxcMeULlNFtsHIQqkiWQpxHJFFIYKjvgMnoxbUgioSvNwxvECQaZcqtUPzXSgODtJkQledgRpGWPJOSmnxilHoYAOeUzcextURscQa

mTJRhcdpZKNVduJBRZIqW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UhMdWFpHiJMfifISgghFlLZiljHnxiuNuwBPKYvzjOmCXPsyQgzwGnTJwwHiJONmW
gxhPAsgjWTTUrPQjZNclYGrrnUWbPddRjBiqcHiDTWsGatYiTSponzqUTZdZrvvuuBDBtTGlDhGoZyHNqJzSiVJUtxSooqqVdDgoGDCOvNJPIayhUZyznkHqTGNDoyVzrJeKWng
ERTsQdhoAKeqotbJjCyPbMhagTwChLsrYcGLVGpcdZrctBQLpcOEVtXQKsvRpWbQHgPvrjiiUVvqXFhPnvvNWqvlHwNFhnoLxiIDKsZPIGPTcwjwXGGiMzwtOvUfMzRVkglqsgA
fIvGMomyDbVcgJCQmtirepxwefjnvHyyiAOLVYSoGVQhJSoHmCEOYOnsogOPMJdznVzZCbviFrAjCWhZEGdkfbKSXlKEzBrjoEuqvCGKTPGYHzmMTyaUYEfrwnkfQJuzoNwRoUE
JOEVyxEzodAlAWAABADuDbAmKEAGCtlePCYzOGpCTQXKCZQuNxooVYYaulUMFIxeMVCbVgaPRzRaicoUxbkIiIjIgBTotetYbEBPFJsptCDZZuuuhIAkbqIDKNTMnbXvSxonoXa

``````
Your code is throwing a seg fault on my machine when i = 206 on line 26:
store[inp[j]] = store[i-1][j];
Check input and AC output for thousands of problems on uDebug!

hoimo
New poster
Posts: 18
Joined: Sun Sep 23, 2012 3:43 am

### Re: 306 Cipher (WA)

What should i do?
Is there is any problem with logic?

hoimo
New poster
Posts: 18
Joined: Sun Sep 23, 2012 3:43 am

### Re: 306 Cipher (WA)

What should i do?
Is there is any problem with logic?

kainfreeman
New poster
Posts: 4
Joined: Wed Nov 19, 2014 8:06 pm

### WA

Can anyone help me to check my code? I tested with all test cases here but no issue detected

Code: Select all

``````AC
}

``````
Last edited by kainfreeman on Sat Nov 22, 2014 8:10 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 306 - Cipher

Don't read and write to files.
Check input and AC output for thousands of problems on uDebug!

kainfreeman
New poster
Posts: 4
Joined: Wed Nov 19, 2014 8:06 pm

### Re: 306 - Cipher

brianfry713 wrote:Don't read and write to files.
I'll remove it when submit. It's not a problem sir.
(Submit with freopen -> CE. But i got WA)
Thanks

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 306 - Cipher

Post the code you'd actually submit.
Check input and AC output for thousands of problems on uDebug!

kainfreeman
New poster
Posts: 4
Joined: Wed Nov 19, 2014 8:06 pm

### Re: 306 - Cipher

Code: Select all

``````AC
``````
Can i have your email for fast conversation? Ty
Last edited by kainfreeman on Sat Nov 22, 2014 8:11 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 306 - Cipher

For the sample input, your code doesn't match the sample output. Instead of the second space, you are printing a null char.
Check input and AC output for thousands of problems on uDebug!

kainfreeman
New poster
Posts: 4
Joined: Wed Nov 19, 2014 8:06 pm

### Re: 306 - Cipher

brianfry713 wrote:For the sample input, your code doesn't match the sample output. Instead of the second space, you are printing a null char.
Thanks alot. I have to fill all chars to space.

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 306 - Cipher

Here's a really clear explanation on how to find the cycle lengths for this problem

http://www.algebra.com/algebra/homework ... 67428.html
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

galibear
New poster
Posts: 1
Joined: Sat Apr 09, 2016 12:51 pm

### Re: 306 - Cipher

Tried every testcase posted in this thread and from uDebug. I am getting Runtime Error. Could anyone help me point out the problem? TIA

Code: Select all

``````import java.util.*;
import java.io.*;

public class Uva306
{
public static void main(String args[]) throws Exception
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line = new String();
String str = new String();
int len;
while ((line = in.readLine()) != null)
{
int numOfChars = Integer.parseInt(line);

if (numOfChars == 0)
break;

line = in.readLine();
StringTokenizer stk = new StringTokenizer(line);
int[] indices = new int[numOfChars];
for (int i = 0; i < numOfChars; i++)
{
indices[i] = Integer.parseInt(stk.nextToken()) - 1;
}

int[] cycles = new int[numOfChars];
for (int i = 0; i < numOfChars; i++)
{
int numOfCycles = 1;
int current = indices[i];

while (i != current)
{
numOfCycles++;
current = indices[current];
}
cycles[i] = numOfCycles;
}

while ((line = in.readLine()) != null)
{
stk = new StringTokenizer(line, " ");
str = stk.nextToken();
int k = Integer.parseInt(str);

if (k == 0)
break;

str = line.substring(line.indexOf(str) + str.length() + 1);

len = str.length();

int charsToPad = numOfChars - len;
for (int i = 0; i < charsToPad; i++)
str += " ";

StringBuilder strbldr = new StringBuilder(str);
for (int i = 0; i < numOfChars; i++)
{
int reps = k % cycles[i];
int position = i;
for (int j = 0; j < reps; j++)
{
position = indices[position];
}
strbldr.setCharAt(position, str.charAt(i));
}
System.out.println(strbldr.toString());
}
System.out.println();
}
}
}``````

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 306 - Cipher

galibear wrote:Tried every testcase posted in this thread and from uDebug. I am getting Runtime Error. Could anyone help me point out the problem? TIA
See
https://uva.onlinejudge.org/index.php?o ... &Itemid=30
Renamed your class to

Code: Select all

``Main``
.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.