Write a program which takes 10 strings from the user and saves it in the vector container. Then, using map - an associative container - process the vector, so that in the end, the map contains strings as keys and number of occurrences as a value.
#include <iostream>
//#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
//Declare Variables
char string[10][30]; //2D array for storing strings
int i, n;
cout<<"Enter number of strings to input\n"<<endl;
cin>>n;
//Read the string from user
cout<<"Enter Strings one by one: \n"<<endl;
for(i=0; i< n ; i++) {
cin>>string[i];
}
//Print the length of each string
cout<<"The length of each string: \n"<<endl;
for(i=0; i< n ; i++) {
//Print the string at current index
cout<<string[i]<<endl;
//Print the length using `strlen` function
cout<<strlen(string[i])<<endl;
}
//Return to the system
return 0;
}
Comments
Leave a comment