-
Notifications
You must be signed in to change notification settings - Fork 0
/
ball.cpp
56 lines (55 loc) · 1.27 KB
/
ball.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
#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
cin >> n;
string input;
cin >> input;
int i = 0;
char first = input[0];
char last = input[n - 1];
int sum = 0;
int parcial = 0;
bool onlyLeft = true;
bool onlyRight = true;
if(first == '>' && last == '<'){
cout << 0 << endl;
onlyLeft = false;
onlyRight = false;
}
else{
if(first == '<'){
int i = 0;
while(i < n){
first = input[i];
if(first == '<'){
parcial++;
} else{
sum += parcial;
onlyLeft = false;
break;
}
i++;
}
}
if(last == '>'){
parcial = 0;
int i = n;
while(i){
i--;
last = input[i];
if(last == '>'){
parcial++;
} else{
sum += parcial;
onlyRight = false;
break;
}
}
}
}
if(onlyLeft || onlyRight) cout << parcial << endl;
else if(sum != 0) cout << sum << endl;
return 0;
}