Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #define MAX 100
- void encode(char *s, int length, int k)
- {
- int n;
- for (int i = 0; i < length; ++i)
- {
- if (!isalpha(s[i])) continue;
- s[i] = toupper(s[i]);
- n = s[i];
- n += k;
- while (n > 'Z')
- n -= 26;
- s[i] = (char)n;
- }
- }
- void decode(char *s, int length, int k)
- {
- int n;
- for (int i = 0; i < length; ++i)
- {
- if (!isalpha(s[i])) continue;
- s[i] = toupper(s[i]);
- n = s[i];
- n -= k;
- while (n < 'A')
- n += 26;
- s[i] = (char)n;
- }
- }
- int main()
- {
- FILE *infile = fopen("Cau3.INP", "r");
- FILE *outfile = fopen("Cau3.OUT", "w");
- int n;
- fscanf(infile, "%d", &n);
- // Clear input buffer
- while (fgetc(infile) != '\n');
- char s1[MAX];
- char s2[MAX];
- fgets(s1, MAX, infile);
- fgets(s2, MAX, infile);
- int l1 = strlen(s1);
- int l2 = strlen(s2);
- encode(s1, l1, n);
- decode(s2, l2, n);
- fprintf(outfile, "%s", s1);
- fprintf(outfile, "%s", s2);
- fclose(infile);
- fclose(outfile);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement