洛谷,0分求助,pls

P1079 [NOIP2012 提高组] Vigenère 密码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string m,key;
    char k;
    cin>>m>>key;
    for(int i=0;i<m.size();i++)
    {
        k=key[i%key.size()];
        if(k>='A' && k<='Z')
        {
            if(m[i]>='A' && m[i]<='Z')
            {
                cout<<char(((m[i]-'A')+(k-'A'))%26);
            }
            else if(m[i]>='a' && m[i]<='z')
            {
                cout<<char(((m[i]-'a')+(k-'A'))%26);
            }
        }
        else if(k>='a' && k<='z')
        {
            if(m[i]>='A' && m[i]<='Z')
            {
                cout<<char(((m[i]-'A')+(k-'a'))%26);
            }else if(m[i]>='a' && m[i]<='z')
            {
                cout<<char(((m[i]-'a')+(k-'a'))%26);
            }
        }
    }
    return 0;
}

求助

核心代码

string k, c, m;
    cin >> k >> c;
    m = c;
    int len = k.size();
    for (int i=0; i<len; ++i)
        k[i] = toupper(k[i]);
    for (int i=0; i<c.size(); ++i) {
        m[i] = (c[i]>='a')?'a':'A';
        c[i] = toupper(c[i]);
        m[i] += (c[i] - k[i%len] + 26) % 26;
    }
    cout << m << endl;

@杨北辰