Контроля за количеством символов и их кодами нет. Если надо, скажи, добавлю, если буду на связи.
#include
#include
const std::string az = "abcdefghijklmnopqrstuvwxyz";
const std::string AZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int is_az(const char c)
{
for(int x = 0; x < 26; x++)
if(az[x] == c)
return x+1;
return 0;
}
int is_AZ(const char c)
{
for(int x = 0; x < 26; x++)
if(AZ[x] == c)
return x+1;
return 0;
}
std::string str_forvard(std::string str, int k)
{
std::string rc = "";
int pos;
for(int x = 0; x < str.length(); x++)
{
pos = is_az(str.at(x));
if(pos)
{
pos += (k - 1);
if(pos < 0)
rc += az.at(pos+26);
else if(pos >= 26)
rc += az.at(pos - 26);
else
rc += az.at(pos);
}
else
{
pos = is_AZ(str.at(x));
if(pos)
{
pos += (k - 1);
if(pos < 0)
rc += AZ.at(pos+26);
else if(pos >= 26)
rc += AZ.at(pos - 26);
else
rc += AZ.at(pos);
}
else
rc += str.at(x);
}
}
return rc;
}
std::string str_back(std::string str, int k)
{ // эту функцию можно удалить. Она для наглядности, если надо мотать алфавит назад.
std::string rc = "";
int pos;
for(int x = 0; x < str.length(); x++)
{
pos = is_az(str.at(x));
if(pos)
{
pos += (-k - 1);
if(pos < 0)
rc += az.at(pos+26);
else if(pos >= 26)
rc += az.at(pos - 26);
else
rc += az.at(pos);
}
else
{
pos = is_AZ(str.at(x));
if(pos)
{
pos += (k - 1);
if(pos < 0)
rc += AZ.at(pos+26);
else if(pos >= 26)
rc += AZ.at(pos - 26);
else
rc += AZ.at(pos);
}
else
rc += str.at(x);
}
}
return rc;
}
int main()
{
std::string str1,str2;
int k = 3;
getline(std::cin,str1);
str2 = str_forvard(str1, k);
std::cout