Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the solution to the problem caesar cipher #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Solutions to Known Problems/Caesar Cipher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//https://www.hackerrank.com/challenges/caesar-cipher-1/problem
#include <bits/stdc++.h>

using namespace std;

string caesarCipher(string s, int k) {
k=k%26;
long int c;
for(int i=0;s[i];i++)
{
if(s[i]!='`')
{
c=s[i];
if(c<=90 && c>=64)
{
c+=k;
if(c>'Z')
c-=26;
}
else if(c<=122 && c>=96)
{
c+=k;
if(c>'z')
c-=26;
}
s[i]=(char)c;
}
}
return s;

}

int main()
{
ofstream fout(getenv("OUTPUT_PATH"));

int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');

string s;
getline(cin, s);

int k;
cin >> k;
cin.ignore(numeric_limits<streamsize>::max(), '\n');

string result = caesarCipher(s, k);

fout << result << "\n";

fout.close();

return 0;
}