首页 > 其他 > 详细

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

时间:2018-10-03 11:16:36      阅读:215      评论:0      收藏:0      [点我收藏+]

题目: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;
}

 

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

原文:https://www.cnblogs.com/Narh/p/9739225.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!