ZOJ 3487 Ordinal Numbers
原创
©著作权归作者所有:来自51CTO博客作者qq636b7aec0b3f1的原创作品,请联系作者获取转载授权,否则将追究法律责任
- 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
Each test case consists of a cardinal number 0 ≤ n
Output
For each test case, output the corresponding ordinal number.
Sample Input
1st
2nd
3rd
4th
1024th
References
简单题
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ms(x,y) memset(x,y,sizeof(x))
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define per(i,j,k) for(int i=j;i>=k;i--)
#define loop(i,j,k) for (int i=j;i!=-1;i=k[i])
#define inone(x) scanf("%d",&x)
#define intwo(x,y) scanf("%d%d",&x,&y)
#define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z)
typedef long long LL;
const int low(int x) { return x&-x; }
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
int T, n;
char s[4][4] = { "th","st","nd","rd" };
int main()
{
for (inone(T); T--;)
{
inone(n);
printf("%d", n);
if (n / 10 % 10 != 1 && n % 10 && n % 10 < 4) puts(s[n % 10]);
else puts(s[0]);
}
return 0;
}