#include <iostream> #include <string> #include <math.h> using namespace std; int main() { int t; while (cin >> t) { for (int i = 0; i < t; ++i) { int n; cin >> n; cout << n; int ten = n / 10 % 10; if (ten == 1) { cout << "th" << endl; } else { if (n % 10 == 1) cout << "st" << endl; else if (n % 10 == 2) cout << "nd" << endl; else if (n % 10 == 3) cout << "rd" << endl; else cout << "th" << endl; } } } return 0; } |
Double click to view unformatted code.