Company Tesla has kept a contest for catchy caption for the image. They have a rule that the caption should not be more than 10 words. If the caption of a candidate is more than 10 words, then the candidature stands to be disqualified. Can you write a program to check whether a caption is eligible for the contest or not.
The maximum sizeof the caption is of 100 bytes.
[Hint:Use functions defined in cstring]
Answers
Answer:
#include <stdio.h>
#include <string.h>
int main()
{
char s[200];
int count = 0, i;
scanf("%[^\n]s", s);
for (i = 0;s[i] != '\0';i++)
{
if (s[i] == ' ' && s[i+1] != ' ')
count++;
}
if((count+1)<10)
printf("Caption eligible for the contest");
else
printf("Caption not eligible for the contest");
}
Explanation:
All hidden test cases passed
Answer:
#include <cstring>
#include <iostream>
int main()
{
int count=0;
char str[100];
std::cin.getline(str,100);
//std::cout<<str;
int len=strlen(str);
for(int i=0;i<len;i++)
{
if(str[i]==' ')
{
count++;
}
}
if(count<=10)
{
std::cout<<"Caption eligible for the contest";
}
else
{
std::cout<<"Caption not eligible for the contest";
}
}
Explanation: