A company provides network encryption for secure data transfer. The data string is encrypted prior to transmission and gets decrypted at the receiving end. But due to some technical error, the encrypted data is lost and the received string is different from the original string by 1 character. Arnold, a network administrator, is tasked with finding the character that got lost in the network so that the bug does not harm other data that is being transferred through the network. Write an algorithm to help
Arnold find the character that was missing at the receiving end but present at the sending end.
Input: The input consists of two space-separated strings – stringSent and stringRec, representing the string that was sent through the network, and the string that was received at the receiving end of the network, respectively.
Output: Print a character representing the character that was lost in the network during transmission and if there is no data loss during transmission then print “NA”.
Constraints
NA
Example
Input: abcdfjgerj abcdfijger
Output: j
Explanation: The character ‘j’ at the end of the sent string was lost in the network during transmission.
Solution in C
#include <stdio.h>
int main()
{
char stringSent[1000],stringRec[1000];
scanf("%s %s", stringSent,stringRec);
int i;
for(i=0;stringSent[i]!='\0';i++)
{
if(stringSent[i]!=stringRec[i])
{
printf("%c",stringSent[i]);
break;
}
}
if(stringSent[i]=='\0')
printf("NA");
}
Comments