Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- bool isDigits(string& s, int from, int to) {
- for (int i = from; i <= to; i++)
- if (!isdigit(s.at(i)))
- return false;
- return true;
- }
- bool isTNumber(string& word) {
- int lenght = word.length();
- if (lenght < 7 || lenght > 9)
- return false;
- switch (lenght) {
- case 7: // xxx-xxx
- return isDigits(word, 0, 2) && isDigits(word, 4, 6) && word[3] == '-';
- case 9: // xxx-xx-xx
- return isDigits(word, 0, 2) && isDigits(word, 4, 5) && word[3] == '-' && isDigits(word, 7, 8) && word[6] == '-';
- case 8: // xx-xx-xx
- return isDigits(word, 0, 1) && isDigits(word, 4, 5) && word[2] == '-' && isDigits(word, 6, 7) && word[5] == '-';
- default:
- return false;
- }
- }
- int main() {
- ifstream in ("f1.txt");
- ofstream out("f2.txt");
- string temp;
- while (in)
- if (in >> temp && isTNumber(temp))
- out << temp << endl;
- in.close();
- out.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement