ZOJ - 3487 Ordinal Numbers

来源:互联网 发布:淘宝网百丽女鞋 编辑:程序博客网 时间:2024/05/17 17:43
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

512341024

Sample Output

1st2nd3rd4th1024th

References

  • http://en.wikipedia.org/wiki/Names_of_numbers_in_English
  • http://en.wikipedia.org/wiki/Ordinal_number_(linguistics)

Author: WU, Zejun
Contest: The 8th Zhejiang Provincial Collegiate Programming Contest


原题:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3487



寒假做的省赛真题,当训练赛来做,全程不知道在干吗,经常有杂事打扰,就A了几道水题,以后做比赛的时候要关机专注。

简单的水题,大意为:十位数是1,全部加th;否则按英语规则来

下面是代码

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;int main(){    int T;    cin>>T;    int a;    while(T--)    {        cin>>a;        int ans=a/10%10;        int tem=a%10;        //cout<<ans<<endl;        if(ans!=1)        {            if(tem==1)            {                cout<<a<<"st"<<endl;                continue;            }            if(tem==2)            {                cout<<a<<"nd"<<endl;                continue;            }            if(tem==3)            {                cout<<a<<"rd"<<endl;                continue;            }            else            {                                cout<<a<<"th"<<endl;                continue;            }        }        else            cout<<a<<"th"<<endl;    }    return 0;}

0 0
原创粉丝点击