Skip to content

Instantly share code, notes, and snippets.

@tabvn
Created October 4, 2018 03:03
Show Gist options
  • Select an option

  • Save tabvn/28c8ebc2a1728d5c8b32571c35fccc29 to your computer and use it in GitHub Desktop.

Select an option

Save tabvn/28c8ebc2a1728d5c8b32571c35fccc29 to your computer and use it in GitHub Desktop.
Đọc số có 2 chữ số
#include <iostream>
#include <string>
using namespace std;
string docHangChuc(int n){
string s;
switch (n) {
case 0:
s = "khong";
break;
case 1:
s = "mot";
break;
case 2:
s = "hai";
break;
case 3:
s = "ba";
break;
case 4:
s = "bon";
break;
case 5:
s = "nam";
break;
case 6:
s = "sau";
break;
case 7:
s = "bay";
break;
case 8:
s = "tam";
break;
case 9:
s = "chin";
break;
case 10:
s = "muoi";
break;
default:
break;
}
return s;
}
string docHangDonVi(int n){
string s;
switch (n) {
case 1:
s = "mot";
break;
case 2:
s = "hai";
break;
case 3:
s = "ba";
break;
case 4:
s = "bon";
break;
case 5:
s = "lam";
break;
case 6:
s = "sau";
break;
case 7:
s = "bay";
break;
case 8:
s = "tam";
break;
case 9:
s = "chin";
break;
default:
break;
}
return s;
}
string doc(int num, int hc, int hdv){
string s = "";
if(num == 10){
s = "muoi";
}
else if(num < 10){
s = docHangChuc(num);
}
else if(num > 10 && num < 20){
s+= "muoi";
if(hdv > 0){
s+= " ";
s+= docHangDonVi(hdv);
}
}
else if (num >= 20 && num <=99){
s+= docHangChuc(hc);
s+= " muoi";
if(hdv > 0){
s+= " ";
s+= docHangDonVi(hdv);
}
}
else{
s = "chua biet doc";
}
return s;
}
int main(){
int n, num, hdv, hc;
cin >> n;
int arr[n];
for (int i =0; i<n; i++) {
cin >> num;
arr[i] = num;
}
for (int i =0; i< n; i++) {
num = arr[i];
hdv = num % 10;
hc = (num/10) % 10;
cout << doc(num, hc, hdv) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment