Untitled
unknown
plain_text
a year ago
2.4 kB
3
Indexable
Never
#include <iostream> #include <cstring> using namespace std; const int LEN_OF_ZTN = 100; const int LEN_OF_NUM = 6; void transition(char **subNumCnt, int numberCnt); int main() { char manyNumber[LEN_OF_ZTN] = {0}; cin >> manyNumber; char *location = manyNumber; int commaNum = 0; char *howManyNum = strchr(manyNumber,','); char *loadingBar = strchr(manyNumber,','); while(howManyNum != NULL) { commaNum++; howManyNum = strchr(howManyNum + 1 ,','); } int numberCnt = commaNum + 1; char **subNumCnt = new char*[numberCnt]; for(int i = 0; i < numberCnt; i++) { subNumCnt[i] = new char[LEN_OF_NUM](); } int subNum = 0; while(loadingBar != NULL) { strncpy(subNumCnt[subNum], location, loadingBar - location); location = loadingBar + 1; loadingBar = strchr(loadingBar + 1, ','); subNum++; } strcpy(subNumCnt[numberCnt - 1], location); transition(subNumCnt, numberCnt); return 0; } void transition(char **subNumCnt, int numberCnt) { bool isFirst = true; for(int i = 0; i < numberCnt; i++) { if(isFirst == true) { isFirst = false; } else { cout << ","; } if(strcmp(subNumCnt[i], "one") == 0) { cout << "1"; } else if(strcmp(subNumCnt[i], "two") == 0) { cout << "2"; } else if(strcmp(subNumCnt[i], "three") == 0) { cout << "3"; } else if(strcmp(subNumCnt[i], "four") == 0) { cout << "4"; } else if(strcmp(subNumCnt[i], "five") == 0) { cout << "5"; } else if(strcmp(subNumCnt[i], "six") == 0) { cout << "6"; } else if(strcmp(subNumCnt[i], "seven") == 0) { cout << "7"; } else if(strcmp(subNumCnt[i], "eight") == 0) { cout << "8"; } else if(strcmp(subNumCnt[i], "nine") == 0) { cout << "9"; } else if(strcmp(subNumCnt[i], "zero") == 0) { cout << "0"; } } return; }