解法一:字符串处理

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. ios::sync_with_stdio(false);
  5. cin.tie(0);
  6. string str1, str2;
  7. cin >> str1 >> str2;
  8. int A[3], B[3];
  9. int tmp = 0;
  10. int index = 0;
  11. for (auto &it:str1) {
  12. if (it == '.') {
  13. A[index++] = tmp;
  14. tmp = 0;
  15. } else {
  16. tmp = tmp * 10 + it - 48;
  17. }
  18. }
  19. A[2] = tmp;
  20. index = 0;
  21. tmp = 0;
  22. for (auto &it:str2) {
  23. if (it == '.') {
  24. B[index++] = tmp;
  25. tmp = 0;
  26. } else {
  27. tmp = tmp * 10 + it - 48;
  28. }
  29. }
  30. B[2] = tmp;
  31. int c;
  32. A[2] += B[2];
  33. c = A[2] / 29;
  34. A[2] %= 29;
  35. A[1] += B[1] + c;
  36. c = A[1] / 17;
  37. A[1] %= 17;
  38. A[0] += B[0] + c;
  39. cout << A[0] << "." << A[1] << "." << A[2] << "\n";
  40. }