您的位置:首页 > 其它

健康运动-合理运动方案[我写绿色IT]

2008-09-08 14:51 232 查看
原题:
Description 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

分析:
题意就是让输出对应的英文缩写。。。
上原码:
#include<stdio.h> int main()  {      int t, n, m;      scanf("%d", &t);      while(t--)      {          scanf("%d", &n);          if((n / 10) % 10 == 1)           printf("%dth\n", n);          else          {              m = n % 10;              printf("%d", n);              if(m == 1) puts("st");              else if(m == 2) puts("nd");              else if(m == 3) puts("rd");              else puts("th");          }      }      return 0;  }


本文出自 “丙三醇” 博客,请务必保留此出处http://bingsanchun.blog.51cto.com/7608078/1271374
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: