1

    1. import java.util.*;
    2. public class Main {
    3. public static void main(String[] args) {
    4. Scanner cin = new Scanner(System.in);
    5. String s = cin.next();
    6. int n = s.length();
    7. int res = 0;
    8. for (int i = 0; i < n; ) {
    9. int j = i;
    10. if ((s.charAt(j) < '0' || s.charAt(j) > '9') && s.charAt(j) != '-') {
    11. i ++;
    12. continue;
    13. }
    14. if (s.charAt(j) == '-') {
    15. j ++;
    16. int t = 0;
    17. while (s.charAt(j) >= '0' && s.charAt(j) <= '9') {
    18. t = t * 10 + (s.charAt(j) - '0');
    19. j++;
    20. }
    21. t = -t;
    22. res += t;
    23. i = j;
    24. } else {
    25. res += s.charAt(j) - '0';
    26. j ++;
    27. i = j;
    28. }
    29. }
    30. System.out.println(res);
    31. }
    32. }

    2
    3

    1. import java.util.*;
    2. public class Main {
    3. public static void main(String[] args) {
    4. Scanner cin = new Scanner(System.in);
    5. String ss = cin.next();
    6. String[] s = ss.split(",");
    7. int n = s.length;
    8. int[] a = new int[n], b = new int[n];
    9. for (int i = 0; i < n; ++i) {
    10. a[i] = Integer.parseInt(s[i]);
    11. b[i] = Integer.parseInt(s[i]);
    12. }
    13. Arrays.sort(b);
    14. int[] res = new int[n];
    15. Arrays.fill(res, -1);
    16. int j = 0;
    17. for (int i = n - 1; i >= 0; --i) {
    18. while (true) {
    19. if (j == n) {
    20. j = 0;
    21. }
    22. if (a[j] == b[i] && res[j] == -1) {
    23. break;
    24. }
    25. j++;
    26. }
    27. res[j] = n - i - 1;
    28. }
    29. for (int i = 0; i < n; ++i) {
    30. System.out.print(res[i]);
    31. if (i != n - 1) {
    32. System.out.print(",");
    33. }
    34. }
    35. }
    36. }