Write a program to print the abbreviation for a given sentence.
Input format:
Get a sentence from the user.
Output Format:
Abbreviate the given sentence. Refer the Sample input and output.
[All text in bold corresponds to input and the rest corresponds to output.]
Sample Input and Output 1:
Enter the sentence
American Standard Code for Information Interchange
The abbreviation is
ASCII
Sample Input and Output 2:
Enter the sentence
Institute of Electrical and Electronics Engineers
The abbreviation is
IEEE
[Hint for C programming: To get a whole sentence use the following statement:
scanf(“%[^\n]”,a);
]
Solution
s = input("Enter the sentence\n ")
#sauravhathi
s = [i for i in s if i.isupper()]
#sauravhathi
print("The abbreviation is\n", "".join(s))
#include<iostream>
#include <cctype>
#include <iostream>
#include <cstring>
using namespace std;
// sauravhathi
int main()
{
string s;
cout<<"Enter the sentence\n";
cin>>s;
string s1 = "";
for(int i=0;i<s.length();i++)
{
if(isupper(s[i]))
{
s1+=s[i];
}
}
cout<<"The abbreviation is\n"<<s1;
return 0;
}
Happy Learning – If you require any further information, feel free to contact me.