Răspuns:
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
ifstream f("schimb.in");
ofstream g("schimb.out");
char s[502], ch, t[502];
short n,k,p,i, len, cod;
void ogl(char s[], short len)
{
for (short j=0; j<len/2; ++j)
swap(s[j],s[len-1-j]);
}
int main()
{
f >> n >> k >> p;
f.get();
for (i=1; i<=n; ++i)
{
f >> s; f.get();
len=strlen(s);
cout << len << "\n";
cod=97+p-1; ch=(char)cod;
if (len<k)
{ ogl(s,len); g << s << "\n"; }
else
{
s[k-1]=ch;
g << s << "\n";
}
}
}
Explicație: