fork(4) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. string s;
  6. while (cin >> s) {
  7. char height = '0';
  8. int hour = 0, length = s.length(), a = 0, b = length - 1;
  9. while(height < ':') {
  10. if (s[a + 1] < s[b - 1]) {
  11. hour += abs(s[a + 1] - height);
  12. height = s[a + 1];
  13. a ++;
  14. } else if (s[a + 1] > s[b - 1]) {
  15. hour += abs(s[b - 1] - height);
  16. height = s[b - 1];
  17. b --;
  18. } else {
  19. hour += abs(s[a + 1] - height);
  20. height = s[a + 1];
  21. a ++;b ++;
  22. }
  23. }
  24. cout << hour << endl;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 4468KB
stdin
073:0
07362:450
06464:36470
0827171:28480
0737491:28180
05374734372747484:184618186912120
stdout
18
28
30
70
66
116