View Code of Problem 50

using namespace std;
int main(){
	string str1,str2;
	getline(cin,str1);
	int len=str1.length();
	int bz;
	for(int i=0;i<len;i++)
	{
		if(isdigit(str1[i])){
			str2.push_back(str1[i]);
			bz=0;
		}
		
		else if((isdigit(str1[i-1])||isdigit(str1[i+1]))&&bz==0)
		{
		 str2.push_back('*');
		 bz=1;
	}
	 } 
	 cout<<str2<<endl;
	return 0;
}
/*
Main.cc: In function 'int main()':
Main.cc:4:2: error: 'string' was not declared in this scope
  string str1,str2;
  ^~~~~~
Main.cc:4:2: note: 'std::string' is defined in header '<string>'; did you forget to '#include <string>'?
Main.cc:1:1:
+#include <string>
 
Main.cc:4:2:
  string str1,str2;
  ^~~~~~
Main.cc:5:10: error: 'cin' was not declared in this scope
  getline(cin,str1);
          ^~~
Main.cc:5:10: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
Main.cc:1:1:
+#include <iostream>
 
Main.cc:5:10:
  getline(cin,str1);
          ^~~
Main.cc:5:14: error: 'str1' was not declared in this scope
  getline(cin,str1);
              ^~~~
Main.cc:5:14: note: suggested alternative: 'std'
  getline(cin,str1);
              ^~~~
              std
Main.cc:5:2: error: 'getline' was not declared in this scope
  getline(cin,str1);
  ^~~~~~~
Main.cc:10:6: error: 'isdigit' was not declared in this scope
   if(isdigit(str1[i])){
      ^~~~~~~
Main.cc:11:4: error: 'str2' was not declared in this scope
    str2.push_back(str1[i]);
    ^~~~
Main.cc:11:4: note: suggested alternative: 'std'
    str2.push_back(str1[i]);
    ^~~~
    std
Main.cc:17:4: error: 'str2' was not declared in this scope
    str2.push_back('*');
    ^~~~
Main.cc:17:4: note: suggested alternative: 'std'
    str2.push_back('*');
    ^~~~
    std
Main.cc:21:3: error: 'cout' was not declared in this scope
   cout<<str2<<endl;
   ^~~~
Main.cc:21:3: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
Main.cc:21:9: error: 'str2' was not declared in this scope
   cout<<str2<<endl;
         ^~~~
Main.cc:21:9: note: suggested alternative: 'std'
   cout<<str2<<endl;
         ^~~~
         std
Main.cc:21:15: error: 'endl' was not declared in this scope
   cout<<str2<<endl;
               ^~~~
Main.cc:21:15: note: 'std::endl' is defined in header '<ostream>'; did you forget to '#include <ostream>'?
Main.cc:1:1:
+#include <ostream>
 
Main.cc:21:15:
   cout<<str2<<endl;
               ^~~~
*/

Double click to view unformatted code.


Back to problem 50