Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- char cuv[255][255];
- char text[255];
- int cuvinte, cuvSize;
- int digit[255];
- char chars[255];
- int numOfDigits, numOfChars;
- bool diferitDeZero = false;
- int cifre, caractere, spaces;
- int numOfZeros;
- int main() {
- cin.getline(text, 255);
- for(int i = 0; i < strlen(text); ++i) {
- if(isdigit(text[i])) {
- ++numOfDigits;
- if(text[i] != '0') {
- diferitDeZero = true;
- } else if(text[i] == '0') {
- ++numOfZeros;
- }
- }
- if(text[i] == ' ') {
- ++spaces;
- }
- if(isalpha(text[i])) {
- ++caractere;
- }
- }
- if(spaces + caractere == strlen(text)) {
- cout << "NaN";
- return 0;
- } else if(spaces + numOfDigits == strlen(text)) {
- cout << "CORECT";
- return 0;
- }
- numOfDigits = 0;
- if(spaces == 0 and diferitDeZero == false) {
- if(numOfZeros > 1) {
- int i;
- for(i = strlen(text) - 1; i >= 0; --i) {
- if(text[i] == '0') {
- break;
- }
- }
- strcpy(text + i, text + i + 1);
- }
- for(int i = 0; i < strlen(text); ++i) {
- if(isdigit(text[i])) {
- if(numOfZeros == 1) {
- digit[0] = 0;
- } else {
- chars[numOfChars++] = text[i];
- }
- }
- if(isalpha(text[i])) {
- chars[numOfChars++] = text[i];
- }
- }
- cout << 0;
- cout << endl;
- for(int i = 0; i <= numOfChars; ++i) {
- cout << chars[i] << " ";
- }
- return 0;
- } else if(spaces == 0 and diferitDeZero == true) {
- int primulNrNenul;
- for(int i = 0; text[i]; ++i) {
- if(isdigit(text[i]) and text[i] != '0') {
- primulNrNenul = i;
- break;
- }
- }
- for(int i = 0; i < primulNrNenul; ++i) {
- if(isalpha(text[i]) or text[i] == '0') {
- chars[numOfChars++] = text[i];
- }
- }
- for(int i = primulNrNenul; i < strlen(text); ++i) {
- if(isdigit(text[i])) {
- digit[numOfDigits++] = text[i] - '0';
- }
- if(isalpha(text[i])) {
- chars[numOfChars++] = text[i];
- }
- }
- for(int i = 0; i < numOfDigits; ++i) {
- cout << digit[i];
- }
- cout << endl;
- for(int i = 0; i < numOfChars; ++i) {
- cout << chars[i] << " ";
- }
- return 0;
- } else if(spaces >= 1 and diferitDeZero == false) {
- numOfChars = 0;
- int i;
- for(i = strlen(text) - 1; i >= 0; --i) {
- if(text[i] == '0') {
- break;
- }
- }
- strcpy(text + i, text + i + 1);
- for(int i = 0; i < strlen(text); ++i) {
- if(isalpha(text[i]) or text[i] == '0') {
- chars[numOfChars++] = text[i];
- }
- }
- cout << 0 << endl;
- for(int i = 0; i <= numOfChars; ++i) {
- cout << chars[i] << " ";
- }
- return 0;
- }
- numOfChars = 0, numOfDigits = 0;
- int poz;
- for(int i = 0; i < strlen(text); ++i) {
- if(isdigit(text[i]) and text[i] != '0') {
- poz = i;
- break;
- }
- }
- for(int i = 0; i < poz; i++) {
- if(isdigit(text[i]) or isalpha(text[i])) {
- chars[numOfChars++] = text[i];
- }
- }
- for(int i = poz; i < strlen(text); ++i) {
- if(isdigit(text[i])) {
- digit[numOfDigits++] = text[i] - '0';
- }
- if(isalpha(text[i])) {
- chars[numOfChars++] = text[i];
- }
- }
- for(int i = 0; i < numOfDigits; ++i) {
- cout << digit[i];
- }
- cout << endl;
- for(int i = 0; i <= numOfChars; ++i) {
- cout << chars[i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement