chiva13

Untitled

Aug 28th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <fstream>
  4. #include <string>
  5. #include <vector>
  6. using namespace std;
  7. void print_lengths(std::string const& line)
  8. {
  9.     int counter=0;
  10.     std::vector<int> indices;
  11.     int min_len=30;
  12.     for (unsigned int i = 0; i < line.length(); i++)
  13.     {
  14.         if ( (line[i]!=' ') && (line[i]!='.') && (line[i]!='\n'))
  15.         {
  16.             counter++;
  17.         }
  18.         else
  19.         {
  20.             //cout<<counter<<" ";
  21.             if(counter<min_len)
  22.             {
  23.                 min_len=counter;
  24.                 indices.clear();
  25.             }
  26.             if(counter==min_len)
  27.             {
  28.                 indices.push_back(i-counter);
  29.             }
  30.                 counter=0;
  31.         }  
  32.     }
  33.     //cout<<min_len;
  34.     for(unsigned int i=0;i<indices.size();++i)
  35.     {
  36.         cout<<indices[i]<<" ";
  37.         cout<<line.substr(indices[i],min_len)<<"\n";
  38.     }
  39.     std::ofstream ost("output.txt");
  40.     for(unsigned int i=0;i<indices.size();++i)
  41.     {
  42.         ost<<indices[i]<<" ";
  43.         ost<<line.substr(indices[i],min_len)<<"\n";    
  44.     }
  45. }
  46. int main()
  47. {      
  48.     std::string string1;
  49.     std::ifstream ist("input.txt");
  50.     std::getline (ist,string1);
  51.     std::cout << string1<<"\n";
  52.     print_lengths(string1);
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment