Skip to content

Instantly share code, notes, and snippets.

@tinwritescode
Last active April 21, 2020 14:51
Show Gist options
  • Select an option

  • Save tinwritescode/43cbb9bcd903a1178b6cf8693aa7f769 to your computer and use it in GitHub Desktop.

Select an option

Save tinwritescode/43cbb9bcd903a1178b6cf8693aa7f769 to your computer and use it in GitHub Desktop.
#include "function.h"
char* reverseString(char *str) {
const int N = strlen(str);
for(int i = 0; i < N / 2; i++) {
swap(str[i], str[N - i - 1]);
}
return str;
}
void humanlizeString(const char *str) {
const char *name[] = {
"nghin", "trieu", "ti"
};
const char *number[] = {
"khong", "mot", "hai", "ba", "bon",
"nam", "sau", "bay", "tam", "chin"
};
const char *name2[] = {
"tram", "muoi", ""
};
int n = strlen(str);
int readnum;
int pos = 0;
int prefix;
while(n != 0) {
readnum = n % 3 == 0 ? 3 : n % 3;
for(int i = pos; i < pos + readnum; i++) {
cout << number[ str[i] - '0' ] << " " << name2[i - pos] << " ";
}
// cin.ignore(256, ' ');
prefix = n % 3 == 0 ? (n - 1) / 3 : n % 3;
if(prefix - 1 >= 0)
cout << name[prefix - 1] << " ";
cout << flush;
pos = pos + readnum;
n -= readnum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment