I checked several times and everything is working correctly, help me def encryption(txt): cipher = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
encryption_list = [] for i in txt: encryption_list.append(cipher[i]) c = d = c1 = 0 encryption_last_list = [] for i in encryption_list: if d == 0: d += 1 c = i i -= 5
if i < 0: i = 25 - abs(i) encryption_last_list.append(i)
else: c1 = i i -= c c = c1 if i < 0: i = 26 - abs(i) encryption_last_list.append(i)
decodding_list = [] for i in encryption_last_list: for k, v in cipher.items(): if v == i: decodding_list.append(k)
return decodding_list text = input() if len(text) <= 99: c = '' output = encryption(text.lower()) for i in output: c += i print(c) #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ char encrypted[100],desencriptado; int largo, resta; scanf("%s",encrypted); largo=strlen(encrypted); for(int j=0;j<largo;j++){ encrypted[j]-= 97; } encrypted[0]+=26; for(int i=1;i<largo;i++){ while(encrypted[i]<encrypted[i-1]){ encrypted[i]+=26; } } resta=5; for(int n=0;n<largo;n++){ desencriptado=((encrypted[n]-resta)%26)+97; printf("%c", desencriptado); resta=encrypted[n]; } return 0; } using System; namespace EasyHack_ { class Coder { private short[] unicode; private string word; public static readonly string alphabet = "abcdefghijklmnopqrstuvwxyz"; public string GetCoderWord() { this.UnicodeToCoder(); this.SetUnicode(); return this.word; } public string GetOutCoderWord() { this.UnicodeOutCoder(); this.SetUnicode(); return this.word; } public Coder(string word) { this.word = word.ToLower(); this.unicode = new short[word.Length]; this.GetUnicode(); }
public string GetWord () { return this.word; } public short[] GetWordUnicode () { return this.unicode; } private void GetUnicode () { for (int iterable = 0; iterable < unicode.Length; iterable++) { this.unicode[iterable] = (short)Coder.alphabet.IndexOf(this.word[iterable]); } } private void SetUnicode () { this.word = ""; for (int iterable = 0; iterable < unicode.Length; iterable++) { this.word += Coder.alphabet[unicode[iterable]]; } } private void UnicodeToCoder () { if (unicode[0] == 21) unicode[0] = 0; else this.unicode[0] = (this.unicode[0] + 5 > 25) ? (short)(this.unicode[0] + 5 - 25) : (short)(this.unicode[0] + 5); for (int iterable = 1; iterable < this.unicode.Length; iterable++) { this.unicode[iterable] = (this.unicode[iterable] + this.unicode[iterable - 1] > 25) ? (short)((this.unicode[iterable] + this.unicode[iterable - 1]) % 26) : (short)(this.unicode[iterable] + this.unicode[iterable - 1]); } } private void UnicodeOutCoder () { for (int iterable = 1; iterable < this.unicode.Length; iterable++) { while (this.unicode[iterable] < this.unicode[iterable - 1]) this.unicode[iterable] += 26; } short _lastUnicode = this.unicode[0]; if (this.unicode[0] == 0) this.unicode[0] = 21; else this.unicode[0] = (this.unicode[0] - 5 < 0) ? (short)(25 + this.unicode[0] - 5) : (short)(this.unicode[0] - 5); for (int iterable = 0; iterable < this.unicode.Length - 1; iterable++) { short element = this.unicode[iterable + 1]; this.unicode[iterable + 1] -= _lastUnicode; _lastUnicode = element; } } } class Program { public static void Main(string[] args) { string coderWord = Console.ReadLine(); Coder word = new Coder(coderWord); Console.WriteLine(word.GetOutCoderWord()); } } } Edited by author 31.10.2021 14:59 Edited by author 31.10.2021 15:11 Edited by author 03.07.2021 11:15 but I couldn't find any way to delete the post Edited by author 27.01.2020 01:24 Edited by author 27.01.2020 01:24 Edited by author 27.01.2020 01:24 I tried to do it with char input, the same happens. tested everything I could find, but passed all the tests don't know what to do #include <iostream> #include <string> using namespace std; int main() { string alf = "abcdefghijklmnopqrstuvwxyz"; char alp[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; string inp; cin >> inp; short *arr = new short[inp.length()]; short *out = new short[inp.length()]; short prev = 0; for (short i = 0; i < inp.length(); i++) { short num = alf.find(inp[i]) + 1; if (num <= 5) num += 26; while (arr[i - 1] > num) num += 26; arr[i] = --num; } out[0] = arr[0] - 5; for (short i = 1; i < inp.length(); i++) out[i] = arr[i] - arr[i - 1]; for (int i = 0; i < inp.length(); i++) cout << alf[out[i]]; delete[] arr; delete[] out; return 0; } the original answer of fskdkskylp is ansthisone but my accepted code give this answer aêsthisone. my accepted code #include<bits/stdc++.h> using namespace std; int main() { char c[104]; scanf("%s",c); int l=strlen(c); int a[l+5]; int b[l+5]; for(int i=0; i<l; i++) { a[i]=c[i]-'a'; } b[0]=a[0]; if(a[0]<5) { b[0]=b[0]+26; } for(int i=1; i<l; i++) { int j=1; while((b[i]=a[i]+j*26)) { if(b[i]%26==a[i]&& b[i]>=b[i-1]) break; j++; } } printf("%c",b[0]-5+'a'); for(int i=1; i<l; i++) { int j=abs(b[i]-b[i-1]); printf("%c",j+'a'); } printf("\n"); return 0; } test for wrong #14: input a h output v c Hm. Let's try to encrypt this output: v -> 21 + 5 = 26 mod 26 = 0 -> a; c -> 2 + 26 = 28 mod 26 = 2 -> c; So, the correct input must be "ac". P.S. "ah" decodes to "vh". Edited by author 18.03.2018 02:50 Доброго всем времени суток. Прошу помочь разобраться, в чем может состоять проблема моего кода. В NetBeans все компилируется без проблем, здесь же выдается ошибка RuntimeError. Я здесь впервые, поэтому прошу не судить (З.Ы. Руководство по написанию java скриптов прочел и до сих пор не нашел ошибки). Заранее всем спасибо. Hi all! I'm asking you for help, cause my script cannot be run by server java compiler. In NetBeans it works well, but here that's a RuntimeError. Thank you in anvance. import java.util.Scanner; import java.io.PrintWriter; public class Cryptography { final String alphabetStr = "abcdefghijklmnopqrstuvwxyz";
public static void main(String[] args) { new Cryptography().run(); } void run() { Scanner in = new Scanner(System.in, "ISO-8859-1"); PrintWriter out = new PrintWriter(System.out); String word = in.next(); out.println( descript(word) ); out.flush(); }
String descript(String word) { int index = alphabetStr.indexOf( word.charAt( word.length()-1 ) );
if ( word.length()==1 ) return ("" + alphabetStr.charAt(index-5));
index -= alphabetStr.indexOf( word.charAt( word.length()-2 ) ); if ( index<0 ) index += 26; return descript(word.substring(0, word.length()-1)) + alphabetStr.charAt(index); }
} Edited by author 17.02.2017 16:13 Edited by author 17.02.2017 16:15 If "Runtime error" happened than your program compiled successful and crashed while running. As you have RE on 4th test your program passed first 3 tests. > int index = alphabetStr.indexOf( word.charAt( word.length()-1 ) ); > if ( word.length()==1 ) return ("" + alphabetStr.charAt(index-5)); How should it work for string "a" for example? Just before you answered i've found exactly this problem. Thank you! There seems to be some error with the judge, most of the solutions are returning a Fail(checker) status from the judge. My program work correct with all of my test. But i have WA on third test. Can anyone give me some tests? Can you help me? I have WA on third test too. Have you got a test? me too!!! My program work correct with all of my test. But i have WA on third test. Can anyone give me some tests? me too!!! My program work correct with all of my test. But i have WA on third test. Can anyone give me some tests? Try this... --------------- yfnfnfyczs fskdkskylp nymhlaeshsw iwuicujnnxboufnfm mawwnrpdx mawkvyyptrfz nataehllelnne bimdhhycaoinese yfnfnfyfjnad xbduyr ohpb --------------- and answers are: --------------- thisistext ansthisone ilovepeople doyouspeakenglish howareyou howoldareyou inthedeathcar whereareyoufrom thisistheend secret jtim --------------- Good luck ;) There are very good tests. First I had got WA 3, but when I have used these tests, I have understood my mistake (with symbol 'a') and now I have got AC. Thank you, JTim Edited by author 12.11.2008 00:43 I got correct answers for all the test cases listed by Jtim. But I got WA 7 and for anyone wondering why this is so, It's the size of the char array I had. It was 100 and the testcase should have been using 100 chars as well, Therefore Once I increased it by 1 , I got AC. :) Hope this helps others ;) Thank you! VNXtreMe Edited by author 02.02.2015 01:24 Edited by author 02.02.2015 01:24 Edited by author 02.02.2015 01:24 Can yo answer me? Edited by author 27.09.2007 21:43 Edited by author 27.09.2007 21:43 please help me !!!!!!!! I submissions 14 time this is my code #include<stdio.h> int main() { char str0[100]; int str1[100],str2[100],str3[100]; int i,len=0; gets(str0); for(i=0;str0[i]!='\0';i++,len++) str1[i]=str0[i]-'a';
str2[0]=str1[0]; for(i=1;i<len;i++) { str2[i]=str1[i]; while(str2[i]<str2[i-1]) { str2[i]+=26;
} }
str3[0]=str2[0]-5; for(i=0;i<len;i++) str3[i+1]=str2[i+1]-str2[i];
for(i=0;i<len;i++) printf("%c",(str3[i]%26)+'a');
} Edited by author 28.11.2006 22:06 Edited by author 28.11.2006 22:08 not (a[0] in ['a'..'z'])!! What I wanna tell you is that this problem is really easy to solve. You only need to have a really good thinking. Try to find the changes between each letters or numbers. Then you'll work it out! The problem is that you haven't considered the case where str[0]<'a'+5. In this case when you do str[0]-=5 at the end a value lesser than 'a' may be obtained. Hence at the end if (str[0]-=5)<0 then str[0]+=26. Try this test case once bimdhhycaoinese Answer should be whereareyoufrom you get [hereareyoufrom if you havent taken care of the condition. <<jagatsastry>> A lot of Thanks)) <jagatsastry> Thank you very much for explanation <jagatsastry> Thank you very much for explanation var sh,de:string; a:array[1..100]of integer; i,n:Integer; begin readln(sh); n:=length(sh); for i:=1 to n do a[i]:=ord(sh[i])-97; for i:=2 to n do if a[i]<a[i-1] then a[i]:=a[i]+((a[i-1]-a[i])div 26 + 1)*26; for i:=n downto 2 do a[i]:=a[i]-a[i-1]; a[1]:=a[1]-5; de:=''; for i:=1 to n do de:=de+chr(97+a[i] mod 26); writeln(de); end. i didn't understand where is my mistake a[1] can be less than 5. Edited by author 05.08.2011 16:43 Edited by author 05.08.2011 16:43 You are great! I got the same mistake. if you problem input is "adham" . what is output? output is "vdetm" . You should know if the first letter is "a" or "b" or "c" or "d" or "f" (char)("a" + 26) is correct way! i got ac in 14 line c++; 0.015s #include <cstdio> int n,m,i,l,t[201]; char s[201]; int main() { scanf("%s",s); n=0; while(s[n])t[n]=s[n++]-'a'; m=5; for(i=0;i<n;i++) { l=(26+t[i]-m)%26; printf("%c",97+l); m=t[i]; } printf("\n"); return 0; } Edited by author 11.04.2008 23:51 don't use namespace std here! And you will get Ac! sorry but still WA#1 try avoiding \n in the end. At least my AC doesn't. Have you fixed WA1 ? I've go AC. WA#1 took place, cause there is some trash in input. It's very very not fear for admins/judges not to warn about it in problem statement ! Got AC with reading a string, and WA#1 with symbol reading (commented block), but both ways of reading work correctly on my computer. It seems that input consists EOL symbol '\n'. int main() {
char c; int n=0; char sym[101]; int code[101];
scanf("%s",sym); n=strlen(sym); for (int i=0;i<n;i++) code[i]=sym[i]-0x61;
/* while (scanf("%c",&c)!=EOF) { code[n]=c-0x61; n++; } */ ... #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int c,m=5,b='a'; int a,k=0; while((c=getchar())!=-1) { a=(26+(c-b)-m)%26; printf("%c",a+b); m=c-b; } return 0; } i've got an WA#1... Edited by author 04.11.2011 21:08 Hello, Pay attention to your string or char size. Test #7 contains exactly 100 characters which at first, led me to get WA but after realizing my mistake and correcting array size, I could get AC. If you're using cin.get command in C++, don't forget to do something like: char s[1000]; cin.get(s , 1000); Give it more space, it doesn't matter how big your array is. Otherwise it'll lead you to get WA#7. Good luck! Sepehr I solved this problem on my computer and used several tests . It works on all of them, but I keep getting WA 7 and I can't figure out why... If anyone knows what test case is used for #7,please tell me :) Thanks. |
|