Created
November 12, 2012 07:56
-
-
Save Abreto/ce60ede4b55091c3f576 to your computer and use it in GitHub Desktop.
NOIP2012 Day1 - vigenere
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
/* NOIP2012 Day1 - Vigenere */ | |
#include <stdio.h> | |
#include <string.h> | |
#include <ctype.h> | |
#define Rni(ci, ki) ( (ci)-(ki)+((ci)<(ki)?(26):0) ) | |
char M[100]; | |
char K[100]; | |
char C[100]; | |
int main(void) | |
{ | |
int i = 0; | |
int mn = 0, kn = 0; | |
scanf("%s\n%s", K, C); | |
kn = strlen(K); | |
mn = strlen(C); | |
for(i = 0;i < mn;i++) | |
{ | |
int islow = islower(C[i]); | |
K[i%kn] = toupper(K[i%kn]); | |
C[i] = toupper(C[i]); | |
M[i] = Rni(C[i]-'A', K[i%kn]-'A')+'A'; | |
if(islow) M[i] = tolower(M[i]); | |
} | |
M[i] = '\0'; | |
printf("%s", M); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment