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".
Note
The input strings stringSent and string Rec
consist of lowercase and uppercase English
alphabets[i.e. a-z, A-Z].
Example
Input:
abcdfjgerj abcdfjger
Output:j
Answers
Program in Java:
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner Sc = new Scanner(System.in);
System.out.print("Enter the string that was sent through the network: ");
String stringSent = Sc.next();
System.out.print("Enter the string that was received at the receiving end of the network: ");
String stringRec = Sc.next();
int len1 = stringSent.length();
int len2 = stringRec.length();
int flag = 0;
for(int i = 0; i < Math.min(len1,len2); i++)
{
char ch1 = stringSent.charAt(i);
char ch2 = stringRec.charAt(i);
if(ch1 != ch2)
{
System.out.println(ch1);
flag = 1;
}
}
if(len1 > len2)
{
System.out.print(stringSent.substring(len2));
flag = 1;
}
if(flag == 0)
{
System.out.print("NA");
}
}
}
Output:
Enter the string that was sent through the network: abcdfjgerj
Enter the string that was received at the receiving end of the network: abcdfjger
j
Answer:
abcdfgerj abcdfjgerdjdsi