Type the Question

Saturday, February 16, 2019

Question Name:Keywords

#include <stdio.h>
#include <string.h>
struct aviraj
{ 
  char c[50];
}s1[20];
int main()
{
int i ,l,count=0;
 char  temp[10];
  for(i=0;i<10;i++) { 
    scanf("%s",s1[i].c);
  } 
  scanf("%s",temp) ;
 // printf("Keyword is %s\n",temp);
    for(i=0;i<10;i++) { 
if(strcmp(s1[i].c,temp)==0)
{count++;l=i;
 
}
    } 
  if(count>0) {   printf("Keyword is %s\n",temp);

      printf("position is %d",l+1);} 
  else { 
    printf("Keyword not found");
  } 

 return 0;
}

Problem Description

Teacher is having a list of 10 keywords in C language present in a file. The students has to find a particular keywords along with its position for an ordered list.
  • Test Case 1
    Input (stdin)
    for
    while
    if 
    int
    float
    double
    char
    struct
    include
    break
    
    char
    Expected Output
    Keyword is char
    position is 7
  • Test Case 2
    Input (stdin)
    for
    while
    if 
    int
    float
    double
    char
    struct
    include
    break
    
    switch
    Expected Output
    Keyword not found

No comments:

Post a Comment

Question Name:TOWER OF HANOI

#include < bits / stdc ++. h > #define lli long long using namespace std ; lli dp [ 202 ]; int main () { int t , n ; ...