Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main() {
- ifstream in("input.txt");
- ofstream out("output.txt");
- string s;
- getline(in, s);
- out << "+7 ";
- int i = 2, count = 0;
- for (i; i < s.size(); i++) {
- if ((int)s[i] > 47 && (int)s[i] < 58)
- break;
- }
- for (i; i < s.size(); i++) {
- if ((int)s[i] > 47 && (int)s[i] < 58)
- out << s[i];
- else {
- i++;
- break;
- }
- }
- out << " ";
- for (int j = i; j < s.size(); j++) {
- if ((int)s[j] > 47 && (int)s[j] < 58) count++;
- }
- if (count > 4) {
- while (count > 4) {
- if ((int)s[i] > 47 && (int)s[i] < 58) {
- out << s[i];
- count--;
- }
- i++;
- }
- out << "-";
- }
- while (count > 2) {
- if ((int)s[i] > 47 && (int)s[i] < 58) {
- out << s[i];
- count--;
- }
- i++;
- }
- out << "-";
- while (count > 0) {
- if ((int)s[i] > 47 && (int)s[i] < 58) {
- out << s[i];
- count--;
- }
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement