SecretMessage agency Difficulty: easy Max Points: 10 Description SecretMessage agency provides message encoding and decoding services for secure data transfer. The first step in decoding includes removal of special characters and the whitespaces from the message, as special characters and whitespaces do not hold any meaning. Write an algorithm to help the agency find the number of special characters and whitespaces in a given message. Input The input consists of a string message, representing the message that need to be decoded by the agency. Output
SecretMessage agency
Difficulty: easy
Max Points: 10
Description
SecretMessage agency provides message encoding and decoding services for secure data
transfer. The first step in decoding includes removal of special characters and the whitespaces
from the message, as special characters and whitespaces do not hold any meaning.
Write an algorithm to help the agency find the number of special characters and whitespaces in a
given message.
Input
The input consists of a string message, representing the message that need to be decoded by
the agency.
Output
Print an integer representing the number of special characters and whitespaces present in a
given message.
Constraints
NA
Example
Input:
gasgg54@#vscsd!s*
Output:
4
Explanation
The special characters having no meaning are ('@','#';’!’,’*'].
Public Test Cases
# Input Expected Output
1 gasgg54@#vscsd!s* 4
Programming Language: C (GCC 9.2.0)
#include<stdio.h>
int main()
{
char text[1000];
scanf("%[^\n]s",text);
int i=0,c=0;
while(text[i]!='\0')
{
if(!(
(text[i]>='a' && text[i]<='z') ||
(text[i]>='A' && text[i]<='Z') ||
(text[i]>='0' && text[i]<='9') ) )
c++;
i++;
}
printf("%d",c);
}
Comments
Post a Comment