Advertisement
lmarioza

Untitled

Sep 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void printEspacos(int quant) {
  5.     cout << endl;
  6.     for(int i = 0; i < quant*4; i++)
  7.         cout << '.';
  8. }
  9.  
  10. int main(){
  11.     string str;
  12.     while(!cin.eof()) {
  13.         getline(cin,str);
  14.         if(str[0] == '#') cout << str << endl;
  15.         else {
  16.             int chaves = 0, pv = 0;
  17.             bool isFor=false,isString=false;
  18.             for(int i = 0; i < str.size(); i++) {
  19.                 if(isString){
  20.                     cout<< str[i];
  21.                     if(str[i] == '"') isString = false;
  22.                 }
  23.                 else{
  24.                      switch(str[i]) {
  25.                         case '"':
  26.                             cout << '"';
  27.                             isString = true;
  28.                             break;    
  29.                         case '{':
  30.                             printEspacos(chaves);
  31.                             chaves++;
  32.                             cout <<'{';
  33.                             printEspacos(chaves);
  34.                             isFor =false;
  35.                             break;
  36.                         case ';':
  37.                             cout << ';';
  38.                             if(!isFor){
  39.                                 if(str[i+1] != '}')printEspacos(chaves);
  40.                             }
  41.                             break;
  42.                         case 'f':
  43.                             if(str[i+1] == 'o' && str[i+2] == 'r' && str[i+3] == ')')isFor = true;
  44.                             cout << 'f';                
  45.                             break;
  46.                         case '}':
  47.                             chaves--;
  48.                             printEspacos(chaves);
  49.                             cout <<'}';
  50.                             if(str[i+1] != '}')printEspacos(chaves);
  51.                             break;
  52.                         default:
  53.                             cout << str[i];
  54.                             break;
  55.                     }
  56.                 }      
  57.             }
  58.         }        
  59.     }
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement