-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.c
More file actions
96 lines (92 loc) · 2.15 KB
/
functions.c
File metadata and controls
96 lines (92 loc) · 2.15 KB
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
93
94
95
96
//var25
//lab10
#include <stdio.h>
#include <string.h>
typedef long long ll;
const int SZ = 100;
ll gcd(ll a, ll b){
while(a != 0 && b != 0){
if(a > b)
a %= b;
else
b %= a;
}
return a + b;
}
ll lcm(ll a, ll b){
return (a * b) / gcd(a, b);
}
//char all[6] = {' ', '(', '{', '[', '\'', '"'};
char rec(char s[], int i, char s1[], int j){
if(i >= strlen(s)){
printf("%s", s1);
return 0;
}
else{
// '.'
if(i == strlen(s) - 2 && s[i] == '.'){
s1[j] = s[i];
if(s[i + 1] == ' '){
printf("%s\n", s1);
return 0;
}
}
// ' '
else if(s[i] == ' '){
if (i + 2 < strlen(s)){
if(s[i + 1] == ' ' && s[i + 2] == ' '){
rec(s, i + 1, s1, j);
}
else{
s1[j] = s[i];
rec(s, i + 1, s1, j + 1);
}
}
else{
s1[j] = s[i];
rec(s, i + 1, s1, j + 1);
}
}
// pair el
else if(s[i] == '(' || s[i] == '[' || s[i] == '{' || s[i] == '\'' || s[i] == '"'){
if (i + 1 < strlen(s)){
if (s[i + 1] != ' '){
s1[j] = s[i];
rec(s, i + 1, s1, j + 1);
}
else{
s1[j] = s[i];
int q = 1;
while(s[q + i] == ' ') q++;
rec(s, i + q, s1, j + 1);
}
}
else{
s1[j] = s[i];
rec(s, i + 1, s1, j + 1);
}
}
//all symbols
else{
s1[j] = s[i];
rec(s, i + 1, s1, j + 1);
}
}
return 0;
}
int main(){
// 1.
ll x, y;
printf("x and y : ");
scanf("%lld%lld", &x, &y);
getchar();
printf("gcd : %lld\nlcm : %lld\n", gcd(x, y), lcm(x, y));
//5.
char s[SZ];
printf("\nString : ");
scanf("%[^\n]s", s);
int i = 0, j = 0;
char s1[SZ] = "";
rec(s, i, s1, j);
return 0;
}