View Code of Problem 447

#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
	int t; cin >> t;
	while (t--) {
		string str; cin >> str;
		if (str.size() > 1 && str[str.size() - 2] == '1')
			cout << str << "th" << endl;
		else if(str[str.size() - 1] == '1')
			cout << str << "st" << endl;
		else if (str[str.size() - 1] == '2')
			cout << str << "nd" << endl;
		else if (str[str.size() - 1] == '3')
			cout << str << "rd" << endl;
		else 
			cout<< str << "th" << endl;
	}
	
}

Double click to view unformatted code.


Back to problem 447