Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5.  
  6. void format(string s[],int n){
  7.     string ans[n]; 
  8.     for(int i = 0; i < n; i++){
  9.         int count = 0;
  10.         string p;
  11.         for(int j = 0; j < s[i].length();j++){
  12.             if(s[i][j] != ' '){
  13.                 p.push_back(s[i][j]);
  14.                 count = 0;
  15.             }else if(count == 0 && s[i][j] == ' '){
  16.                 p.push_back(s[i][j]);
  17.                 count ++;
  18.             }
  19.         }
  20.         ans[i] = p;
  21.     }for(int i = 0; i < n; i++){
  22.         cout << ans[i];
  23.     }      
  24. }
  25.  
  26.  
  27.  
  28. int main(){
  29.     string in[3];
  30.     in[0] = "asd  asd";
  31.     in[1] = "asd  dsa";
  32.     in[2] = "qweqwe      qwe";
  33.     format(in,3);
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement