Advertisement
Norby9

Untitled

Jul 11th, 2020
1,446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. char cuv[255][255];
  6. char text[255];
  7. int cuvinte, cuvSize;
  8. int digit[255];
  9. char chars[255];
  10. int numOfDigits, numOfChars;
  11. bool diferitDeZero = false;
  12. int cifre, caractere, spaces;
  13. int numOfZeros;
  14.  
  15. int main() {
  16.     cin.getline(text, 255);
  17.     for(int i = 0; i < strlen(text); ++i) {
  18.         if(isdigit(text[i])) {
  19.             ++numOfDigits;
  20.             if(text[i] != '0') {
  21.                 diferitDeZero = true;
  22.             } else if(text[i] == '0') {
  23.                 ++numOfZeros;
  24.             }
  25.         }
  26.         if(text[i] == ' ') {
  27.             ++spaces;
  28.         }
  29.         if(isalpha(text[i])) {
  30.             ++caractere;
  31.         }
  32.     }
  33.     if(spaces + caractere == strlen(text)) {
  34.         cout << "NaN";
  35.         return 0;
  36.     } else if(spaces + numOfDigits == strlen(text)) {
  37.         cout << "CORECT";
  38.         return 0;
  39.     }
  40.     numOfDigits = 0;
  41.     if(spaces == 0 and diferitDeZero == false) {
  42.         if(numOfZeros > 1) {
  43.             int i;
  44.             for(i = strlen(text) - 1; i >= 0; --i) {
  45.                 if(text[i] == '0') {
  46.                     break;
  47.                 }
  48.             }
  49.             strcpy(text + i, text + i + 1);
  50.         }
  51.         for(int i = 0; i < strlen(text); ++i) {
  52.             if(isdigit(text[i])) {
  53.                 if(numOfZeros == 1) {
  54.                     digit[0] = 0;
  55.                 } else {
  56.                     chars[numOfChars++] = text[i];
  57.                 }
  58.             }
  59.             if(isalpha(text[i])) {
  60.                 chars[numOfChars++] = text[i];
  61.             }
  62.         }
  63.         cout << 0;
  64.         cout << endl;
  65.         for(int i = 0; i <= numOfChars; ++i) {
  66.             cout << chars[i] << " ";
  67.         }
  68.         return 0;
  69.     } else if(spaces == 0 and diferitDeZero == true) {
  70.         int primulNrNenul;
  71.         for(int i = 0; text[i]; ++i) {
  72.             if(isdigit(text[i]) and text[i] != '0') {
  73.                 primulNrNenul = i;
  74.                 break;
  75.             }
  76.         }
  77.         for(int i = 0; i < primulNrNenul; ++i) {
  78.             if(isalpha(text[i]) or text[i] == '0') {
  79.                 chars[numOfChars++] = text[i];
  80.             }
  81.         }
  82.         for(int i = primulNrNenul; i < strlen(text); ++i) {
  83.             if(isdigit(text[i])) {
  84.                 digit[numOfDigits++] = text[i] - '0';
  85.             }
  86.             if(isalpha(text[i])) {
  87.                 chars[numOfChars++] = text[i];
  88.             }
  89.         }
  90.         for(int i = 0; i < numOfDigits; ++i) {
  91.             cout << digit[i];
  92.         }
  93.         cout << endl;
  94.         for(int i = 0; i < numOfChars; ++i) {
  95.             cout << chars[i] << " ";
  96.         }
  97.         return 0;
  98.     } else if(spaces >= 1 and diferitDeZero == false) {
  99.           numOfChars = 0;
  100.             int i;
  101.             for(i = strlen(text) - 1; i >= 0; --i) {
  102.                 if(text[i] == '0') {
  103.                     break;
  104.                 }
  105.             }
  106.             strcpy(text + i, text + i + 1);
  107.             for(int i = 0; i < strlen(text); ++i) {
  108.                 if(isalpha(text[i]) or text[i] == '0') {
  109.                     chars[numOfChars++] = text[i];
  110.                 }
  111.             }
  112.             cout << 0 << endl;
  113.             for(int i = 0; i <= numOfChars; ++i) {
  114.                 cout << chars[i] << " ";
  115.             }
  116.             return 0;
  117.  
  118.     }
  119.     numOfChars = 0, numOfDigits = 0;
  120.     int poz;
  121.     for(int i = 0; i < strlen(text); ++i) {
  122.         if(isdigit(text[i]) and text[i] != '0') {
  123.             poz = i;
  124.             break;
  125.         }
  126.     }
  127.     for(int i = 0; i < poz; i++) {
  128.         if(isdigit(text[i]) or isalpha(text[i])) {
  129.             chars[numOfChars++] = text[i];
  130.         }
  131.      }
  132.     for(int i = poz; i < strlen(text); ++i) {
  133.         if(isdigit(text[i])) {
  134.             digit[numOfDigits++] = text[i] - '0';
  135.         }
  136.         if(isalpha(text[i])) {
  137.             chars[numOfChars++] = text[i];
  138.         }
  139.     }
  140.     for(int i = 0; i < numOfDigits; ++i) {
  141.         cout << digit[i];
  142.     }
  143.     cout << endl;
  144.     for(int i = 0; i <= numOfChars; ++i) {
  145.         cout << chars[i] << " ";
  146.     }
  147.     return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement