Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<algorithm>
- #include<vector>
- using namespace std;
- int main() {
- string s;
- cin >> s;
- vector<string> nums;
- vector<string> words;
- vector<pair<int, int> > dots;
- int positions = 0;
- for(int i = 0; i < s.size()+1;) {
- int count = 1, k = i+1;
- if(i == s.size()) {
- dots.push_back(make_pair(0, positions));
- break;
- }
- if(s[i] == '.') {
- while(s[k] == '.' && k < s.size()) {
- count++;
- k++;
- }
- dots.push_back(make_pair(count, positions));
- positions = 0;
- } else
- if(s[i] >= 'a' && s[i] <= 'z') {
- string word;
- word.push_back(s[i]);
- while(s[k] >= 'a' && s[k] <= 'z' && k < s.size()) {
- count++;
- word += s[k];
- k++;
- }
- words.push_back(word);
- positions++;
- } else
- if(s[i] >= '0' && s[i] <= '9') {
- string num;
- num.push_back(s[i]);
- while(s[k] >= '0' && s[k] <= '9' && k < s.size()) {
- count++;
- num.push_back(s[k]);
- k++;
- }
- nums.push_back(num);
- positions++;
- }
- i += count;
- k = i+1;
- }
- int countW = 0, countN = 0;
- for(int i = 0; i < dots.size(); i++) {
- for(int j = 0; j < dots[i].second; j++) {
- if(countN < nums.size()) {
- cout << nums[countN];
- countN++;
- } else if(countW < words.size()) {
- cout << words[countW];
- countW++;
- }
- }
- for(int j = 0; j < dots[i].first; j++) {
- cout << '.';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement