-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindent.cpp
94 lines (75 loc) · 2.76 KB
/
indent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <bits/stdc++.h>
#include <fstream>
#define ll long long
using namespace std;
int main()
{
string line ;
fstream fp("inputf.in") ;
ofstream ofp("outputf.in") ;
int cnt = 1 ;
//int cnt2 = 1 ;
int flag = 0 ;
int flag2 = 0 ;
while( getline( fp , line))
{
char c ;
int pos = 0 ;
//cout << cnt2 << " " ;
// for( int i = 0 ; i < line.length() ; i++)
// {
// c = line[i] ;
// if( !isspace(c)){
// ofp << cnt << " " ;
// cnt++ ;
// break ;
// }
// }
for( int i = 0 ; i < line.length() ; i++)
{
c = line[i] ;
if( !isspace(c) && c == '{' && flag == 1) { flag = 0 ; flag2 = 0 ; ofp << '{' << endl ; continue ;}
if( !isspace(c) && c == '{' ) { ofp << '{' << endl ; continue ; }
if( !isspace(c) && flag2 == 1 ) {
if( c == ';' ) { flag = flag2 = 0 ; }
else {
flag = 0 ;
flag2 = 2 ;
ofp << '{' << endl ;
}
//ofp << cnt << " " ; cnt++ ;
}
ofp << c ;
if( c == '}') ofp << endl ;
if( !isspace(c) && flag2 == 2 && c == ';') { ofp << '}' << endl ; flag2 = 0 ; flag = 0 ; }
if( c == ')') {
flag2 = 1 ;
flag = 1 ;
}
}
ofp << endl ;
// ofp << line << endl;
// cnt++ ;
}
fstream if2("outputf.in") ;
ofstream ofp2("xyz.cpp") ;
while( getline( if2 , line) )
{
char c ;
int pos = 0 ;
for( int i = 0 ; i < line.length() ; i++)
{
c = line[i] ;
if( !isspace(c) && c != '#'){
ofp2 << cnt << " " ;
cnt++ ;
break ;
}
}
ofp2 << line << endl;
// cnt++ ;
}
if2.close() ;
ofp2.close() ;
return 0 ;
}