ZOJ - 3487 Ordinal Numbers
来源:互联网 发布:淘宝网百丽女鞋 编辑:程序博客网 时间:2024/05/17 17:43
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
- zoj 3487 Ordinal Numbers
- ZOJ 3487 Ordinal Numbers
- zoj 3487 Ordinal Numbers
- zoj - 3487 - Ordinal Numbers
- ZOJ 3487 Ordinal Numbers
- ZOJ 3487 Ordinal Numbers
- zoj 3487 Ordinal Numbers
- ZOJ 3487 Ordinal Numbers
- ZOJ - 3487 Ordinal Numbers
- ZOJ 3487Ordinal Numbers
- ZOJ 3487A - Ordinal Numbers
- ZOJ Problem Set - 3487||Ordinal Numbers
- ZOJ 3487Ordinal Numbers(模拟)
- Ordinal Numbers
- A Ordinal Numbers
- ZOJ3487-Ordinal Numbers
- 英文序數寫法與唸法 Ordinal Numbers(轉載)
- 省赛热身赛之Ordinal Numbers
- 插入排序
- 欢迎使用CSDN-markdown编辑器
- 不使用第三方变量交换两个变量的值
- PAT:A1035. Password (20/20)
- Swift3.0 -- didSet(OC中重写setter方法)
- ZOJ - 3487 Ordinal Numbers
- Python小试牛刀之三
- 建造者模式
- 泛型的优点
- .net core中加载lua脚本的类库- MoonSharp
- 机器学习实战笔记_09_树回归_代码错误修正
- poj2291
- 用C/C++进行注释转化
- Solr学习笔记 --- Solr查询页面参数