Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n = 16, prev = 0;
- string current_line = "", final_string = "", word = "";
- 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";
- //string str = "sgfg gd 3223 23 dghdhgh ghfhjjhghjd ghj";
- vector<string>words;
- for(int i = 0; i < str.size(); i++)
- {
- if(str[i] == ' ')
- {
- words.push_back(word);
- word = "";
- }
- else word += str[i];
- }
- int charCount = 0;
- final_string += words[0];
- charCount += words[0].size();
- for(int i = 1; i < words.size(); i++)
- {
- if(charCount + 1 + words[i].size() <= n)
- {
- final_string += " " + words[i];
- charCount += 1 + words[i].size();
- }
- else
- {
- final_string += "\r\n";
- final_string.insert(prev, n - charCount, ' ');
- prev += n + 2;
- final_string += words[i];
- charCount = words[i].size();
- }
- }
- final_string.insert(prev, n - charCount, ' ');
- cout << final_string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement