# Help me in solving CAESAR problem.... why it is only passing one condition

### My code

``````#include <iostream>
using namespace std;

int main() {
int q;
cin >> q;
while(q--)
{
int n;
cin >> n;
string S,T,U;
cin >> S >> T >> U;

int riot;
riot = T[0]-S[0];

for(int i=0;i<U.length();i++)
{
if(riot>=0)
{
U[i] = U[i] + riot;
if(U[i]>122) U[i] = U[i] - 26;
}
else
{
int len = U[i] - 'a';
int diff = riot - len;
if(riot>len)
{
U[i] = 122 - diff;
}
else U[i] = U[i] - riot;
}
}

cout << U << endl;
}
return 0;
}
``````

Problem Link: CAESAR Problem - CodeChef

@dj0o7
U r getting wa because riot can also be negative according to your code so u have to take care of that too.
This in my code i have taken care all the conditions in a much simpler way hope u will get it.
include
using namespace std;

int main() {
int t;
cin>>t;
while(tâ€“)
{
int n;
cin>>n;
string s,t,u;
cin>>s>>t>>u;
int k=(t[0]-s[0]+26)%26;

``````    for(int i=0;i<u.size();i++)
{
int val=(u[i]-'a'+1+k)%26;

if(val==0)
val=26;
u[i]='a'+val-1;
}
cout<<u<<endl;
}
return 0;
``````

}