View Code of Problem 447

#include <iostream>
#include <string>
#include <cstring>
#include <set>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main()
{
	int n, m;
	int i, j,t;
	string s;
	cin >> t;
	while (t--)
	{
		cin >> s;
		n = s.size();
		if (n>1&&s[n - 2] == '1')
			cout << s << "th" << endl;
		else
		{
			if(s[n-1]=='1')
				cout << s << "st" << endl;
			else if (s[n - 1] == '2')
				cout << s << "nd" << endl;
			else if (s[n - 1] == '3')
				cout << s << "rd" << endl;
			else
				cout << s << "th" << endl;
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 447