Another solution can be sort every word and equate it with input word instead of checking occurrence of each letter.
For example if input string is “chef”–after sorting–“cehf”.
Assume input sting be “cfeh”, after sorting it will also become “cehf” which is equal to sorted string of previous input.
I want to know whats wrond with my solution. CodeChef did not accept this solution.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class Jeff
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“ENTER LETTERS THAT JEFF CAN READ”);
String jVoc=br.readLine();
System.out.println(“ENTER NUMBER OF WORDS IN THE BOOK”);
int num=Integer.parseInt(br.readLine());
String word;
for(int i=1;i<=num;i++)
{
System.out.println("ENTER WORD "+i);
word=br.readLine();
boolean canRead=true;
for(int j=0;j<=jVoc.length()-1;j++)
{
char ch=jVoc.charAt(j);
if(word.indexOf(ch)==-1)
{
canRead=false;
break;
}
}
if(canRead==true)
System.out.println(“YES”);
else System.out.println(“NO”);
}
Hello everyone ,
I am getting a wrong ans .
please help
Here is my work #include <stdio.h> #include <string.h>
int main()
{
int t,len1,len2;
char arr[27];
//scanf("%d",&n);
scanf("%s",arr);
len1= strlen(arr);
scanf("%d",&t);
while(t–)
{
char arr2[13];
int flag=0;
len2= strlen(arr2);
scanf("%s",arr2);
for(int i=0;i<len2;i++)
{
for(int j=0;j<len1;j++)
{
if(arr2[i]==arr[j])
{
flag++;
break;
}
}
}
PLEASE CHECK MY CODE ONCE:
My almost all custom inputs are working well and giving out correct solutions, but while SUBMITTING its providing WRONG ANSWER
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s , t1;
cin >> s;
int j , n = s.length();
char char_array[n + 1];
strcpy(char_array, s.c_str());
int t , i;
cin >> t;
for( i = 0 ; i < t ; i++ )
{
cin>>t1;
int k = t1.length();
char char_array2[k + 1];
strcpy( char_array2, t1.c_str() );
int m , a = 0;
for( j = 0 ; j < = k ; j++ )
{
for( m = 0 ; m < = n ; m++ )
{
if( char_array2[j] == char_array[m] )
{
a++;
}
}
}
if(a!=n+1)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
In the above code, there’s a line marked “This line”. If I am using getline, my code was not accepted, but when I used cin, my code was accepted. Any idea why this happened?