c
unknown
plain_text
2 years ago
1.2 kB
13
Indexable
#include <stdio.h>
#include <string.h>
void change(char *a, char *b) //str, key
{
for (int i = 0; i <= strlen(a); i++)
if (a[i] >= 'A' && a[i] <= 'Z')
{
int move = a[i] - 65 + b[i] - 65;
if (move >= 26)
move -= 26;
a[i] = 'A' + move;
}
else if (a[i] >= 'a' && a[i] <= 'z')
{
int move = a[i] - 97 + b[i] - 97;
if (move >= 26)
move -= 26;
a[i] = 'a' + move;
}
}
void bigsmall(char *a, char *b) //str, key
{
for (int i = 0; i <= strlen(a); i++)
{
if (a[i] >= 'A' && a[i] <= 'Z' && b[i] >= 'a' && b[i] <= 'z')
b[i] -= 32;
else if (a[i] >= 'a' && a[i] <= 'z' && b[i] >= 'A' && b[i] <= 'Z')
b[i] += 32;
}
}
int main()
{
char str[100001], key[100001];
scanf("%s %s", str, key);
if (strlen(key) < strlen(str)) //若密鑰字較少,複製
for (int i = strlen(key), j = 0; i < strlen(str); i++, j++)
key[i] = key[j];
bigsmall(str, key);
change(str,key);
puts(str);
return 0;
}Editor is loading...
Leave a Comment