The program must accept three characters ch1, ch2 and ch3 as the input. The program must print Same if the first two characters or the last two characters are same, else print Different as the output.
Note: Print Different, if all the characters are same.
Example Input/Output 1:
Input:
s g g
Output:
Same
Example Input/Output 2:
Input:
a a a
Output:
Different
Example Input/Output 3:
Input:
x y z
Output:
Different
#include <stdio.h>
int main()
{
char ch1,ch2,ch3;
scanf("%c %c %c",&ch1,&ch2,&ch3);
if(ch1!=ch3 && (ch1==ch2 || ch2==ch3))
{
printf("Same");
}
else
{
printf("Different");
}
}
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char ch1 = sc.next().charAt(0);
char ch2 = sc.next().charAt(0);
char ch3 = sc.next().charAt(0);
if (ch1 != ch3 && (ch1 == ch2 || ch2 == ch3)) {
System.out.println("Same");
} else {
System.out.println("Different");
}
}
}
ch1, ch2, ch3 = map(str, input().split())
if ch1 != ch3 and(ch1==ch2 or ch2 == ch3):
print('Same')
else:
print('Different')
#include <iostream>
using namespace std;
int main()
{
char ch1, ch2, ch3;
cin >> ch1 >> ch2 >> ch3;
if(ch1 != ch3 && (ch1 == ch2 || ch2 == ch3))
{
cout << "Same";
}
else
{
cout << "Different";
}
return 0;
}
Leave a Reply