-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da3fa02
commit bfd4975
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |