ALTERING DIGITS
Problem Description
Chef has a number D containing only digits 0s and 1s. He wants to make the number to have all the digits same. For that, he will change exactly one digit, i.e. from 0 to 1 or from 1 to 0. If it is possible to make all digits equal (either all 0s or all 1s) by flipping exactly 1 digit then output "Yes", else print "No" (quotes for clarity)
CODING ARENA
#include<stdio.h>
#include<string.h>
int main()
{
int t,n1,n0,len,i;
char arr[100005];
scanf("%d",&t);
while(t--){
scanf("%s",arr);
n1=n0=0;
len=strlen(arr);
for(i=0;i<len;i++){
if(arr[i]=='0')
++n0;
else
++n1;
}
if(n1==len-1 || n0==len-1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
Test Case 1
Input (stdin)2
101
11
Expected Output
Yes
No
Test Case 2
Input (stdin)2
10
110
Expected Output
Yes
Yes
Change the string
ReplyDeleteQUESTION DESCRIPTION
Abar was given a string S, the task is to change the string according to the condition; If the first letter in a string is capital letter then change the full string to capital letters, else change the full string to small letters.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains a string S.
Output:
For each test case, print the changed string in a new line.
Constraints:
1<=T<=200
1<=|string length|<=104
TEST CASE 1
INPUT
2
geEkS
FoR
OUTPUT
geeks
FOR
TEST CASE 2
INPUT
2
HeLlo
woRLD
OUTPUT
HELLO
world