Advertisement
AlaminSakib

Right Alignment [Enosis]

Dec 9th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n = 16, prev = 0;
  8.     string current_line = "", final_string = "", word = "";
  9.     string str="Dear Sir, It isa Nur Imtiazul Haque from Khulna University of Engineering & Technology, Khulna, Department of Computer Science & Engineering (2k13).I have recently heard that Bording Visa is interested in recruiting Junior Mobile Developer. I have developed some complete android projects. I am also very interested in developing iOS application. I am attaching my CV with this mail as a candidate for the following post. afg";
  10.     //string str = "sgfg gd 3223 23 dghdhgh ghfhjjhghjd ghj";
  11.     vector<string>words;
  12.     for(int i = 0; i < str.size(); i++)
  13.     {
  14.         if(str[i] == ' ')
  15.         {
  16.             words.push_back(word);
  17.             word = "";
  18.         }
  19.         else word += str[i];
  20.     }
  21.     int charCount = 0;
  22.     final_string += words[0];
  23.     charCount += words[0].size();
  24.     for(int i = 1; i < words.size(); i++)
  25.     {
  26.         if(charCount + 1 + words[i].size() <= n)
  27.         {
  28.             final_string += " " + words[i];
  29.             charCount += 1 + words[i].size();
  30.         }
  31.         else
  32.         {
  33.             final_string += "\r\n";
  34.             final_string.insert(prev, n - charCount, ' ');
  35.             prev += n + 2;
  36.             final_string += words[i];
  37.             charCount = words[i].size();
  38.         }
  39.     }
  40.     final_string.insert(prev, n - charCount, ' ');
  41.     cout << final_string;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement