洛谷 1079 Vigenère 密码——模拟水题

题目:https://www.luogu.org/problemnew/show/P1079

大水题。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=105,M=1005;
int n,m;
char a[N],b[N];
int get_int(char ch)
{
    if(ch>='A'&&ch<='Z') return ch-'A'+1;
    return ch-'a'+1;
}
int main()
{
    scanf("%s",a+1); n=strlen(a+1);
    scanf("%s",b+1); m=strlen(b+1);
    int j=0;
    for(int i=1,d;i<=m;i++)
    {
        j++; if(j>n) j=1;
        d=get_int(b[i])+1-get_int(a[j]);
        if(d<=0)d+=26;
        d+=(b[i]>='A'&&b[i]<='Z'?'A'-1:'a'-1);
        printf("%c",d);
    }
    return 0;
}

 

posted on 2018-10-03 09:50  Narh  阅读(130)  评论(0编辑  收藏  举报

导航