Skip to content

Commit

Permalink
Solve Encryption in c
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Aug 20, 2024
1 parent da3fa02 commit bfd4975
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions solutions/beecrowd/1024/1024.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#define MAX_M 1000

void reverse_string(char *string) {
char *start = string;
char *end = start + strlen(string) - 1;
char temp;

while (start < end) {
temp = *start;
*start = *end;
*end = temp;

start++;
end--;
}
}

int main() {
int16_t n;
char line[MAX_M];
scanf("%d", &n);
// hack to force cursor to next line
fgets(line, MAX_M, stdin);

for (uint16_t i = 0; i < n; i++) {
fgets(line, MAX_M, stdin);

size_t line_length = strlen(line);
if (line[line_length - 1] == '\n') {
line[line_length - 1] = '\0';
line_length--;
}

reverse_string(line);

for (uint16_t j = 0; j < line_length; j++) {
if ((line[j] >= 65 && line[j] <= 90) // between A and Z
|| (line[j] >= 97 && line[j] <= 122)) { // between a and z
line[j] = line[j] + 3;
}
if (j >= line_length / 2) {
line[j] = line[j] - 1;
}
}

printf("%s\n", line);
}

return 0;
}

0 comments on commit bfd4975

Please sign in to comment.