Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. ifstream in("input.txt");
  9. ofstream out("output.txt");
  10. string s;
  11. getline(in, s);
  12. out << "+7 ";
  13. int i = 2, count = 0;
  14. for (i; i < s.size(); i++) {
  15. if ((int)s[i] > 47 && (int)s[i] < 58)
  16. break;
  17. }
  18. for (i; i < s.size(); i++) {
  19. if ((int)s[i] > 47 && (int)s[i] < 58)
  20. out << s[i];
  21. else {
  22. i++;
  23. break;
  24. }
  25. }
  26. out << " ";
  27. for (int j = i; j < s.size(); j++) {
  28. if ((int)s[j] > 47 && (int)s[j] < 58) count++;
  29. }
  30. if (count > 4) {
  31. while (count > 4) {
  32. if ((int)s[i] > 47 && (int)s[i] < 58) {
  33. out << s[i];
  34. count--;
  35. }
  36. i++;
  37. }
  38. out << "-";
  39. }
  40. while (count > 2) {
  41. if ((int)s[i] > 47 && (int)s[i] < 58) {
  42. out << s[i];
  43. count--;
  44. }
  45. i++;
  46. }
  47. out << "-";
  48. while (count > 0) {
  49. if ((int)s[i] > 47 && (int)s[i] < 58) {
  50. out << s[i];
  51. count--;
  52. }
  53. i++;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement