Ordinal Numbers(简单)

Ordinal Numbers

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Ordinal numbers refer to a position in a series. Common ordinals include zeroth, first, second, third, fourth and so on. Ordinals are not often written in words, they are written using digits and letters. An ordinal indicator is a sign adjacent to a numeral denoting that it is an ordinal number, rather than a cardinal number. In English, the suffixes -st (e.g. 21st), -nd (e.g. 22nd), -rd (e.g. 23rd), and -th (e.g. 24th) are used. The rules are as follows:

  • If the tens digit of a number is 1, then write "th" after the number. For example: 13th, 19th, 112th, 9311th.
  • If the tens digit is not equal to 1, then use "st" if the units digit is 1, "nd" if the units digit is 2, "rd" if the units digit is 3, and "th" otherwise: For example: 2nd, 7th, 20th, 23rd, 52nd, 135th, 301st.
Input

There are multiple test cases. The first line of input is an integer T ≈ 1000 indicating the number of test cases.

Each test case consists of a cardinal number 0 ≤ n < 1,000,000,000.

Output

For each test case, output the corresponding ordinal number.

Sample Input
5
1
2
3
4
1024
Sample Output
1st
2nd
3rd
4th
1024th
References
 1 #include <iostream>
 2 #include <string>
 3 #include <cstdio>
 4 #include <cmath>
 5 #include <cstring>
 6 #include <algorithm>
 7 #include <map>
 8 #include <vector>
 9 #include <set>
10 #include <queue>
11 #include <stack>
12 #define LL long long
13 #define MAXI 2147483647
14 #define MAXL 9223372036854775807
15 #define eps (1e-8)
16 #define dg(i) cout << "*" << i << endl;
17   
18 using namespace std;
19   
20 int main()
21 {
22     int t, n, m;
23     scanf("%d", &t);
24     while(t--)
25     {
26         scanf("%d", &n);
27         if((n / 10) % 10 == 1) printf("%dth\n", n);
28         else
29         {
30             m = n % 10;  //获得最后一位数字
31             printf("%d", n);
32             if(m == 1) puts("st");
33             else if(m == 2) puts("nd");
34             else if(m == 3) puts("rd");
35             else puts("th");
36         }
37     }
38     return 0;
39 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值