We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here is C# Code. I think it's clear to understand.
usingSystem.Text;usingSystem;classSolution{// Complete the caesarCipher function below.staticstringcaesarCipher(StringBuilders,intk){k%=26;for(inti=0;i<s.Length;i++){inta=Convert.ToInt32(s[i]);if((a>=65&&a<=90)){if(a+k>90)s[i]=(char)(k-Math.Abs(a-90)+64);elses[i]=(char)(a+k);}elseif((a>=97&&a<=122)){if(a+k>122)s[i]=(char)(k-Math.Abs(a-122)+96);elses[i]=(char)(a+k);}}returns.ToString();}staticvoidMain(string[]args){intn=Convert.ToInt32(Console.ReadLine());StringBuilders=newStringBuilder(Console.ReadLine());intk=Convert.ToInt32(Console.ReadLine());stringresult=caesarCipher(s,k);Console.WriteLine(result);}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Caesar Cipher
You are viewing a single comment's thread. Return to all comments →
Here is C# Code. I think it's clear to understand.