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.
For each test case, output the corresponding ordinal number.
512341024Sample Output
1st2nd3rd4th1024thReferences
http://en.wikipedia.org/wiki/Names_of_numbers_in_Englishhttp://en.wikipedia.org/wiki/Ordinal_number_(linguistics)
Author: WU, ZejunContest: The 8th Zhejiang PRovincial Collegiate Programming Contest题意:将阿拉伯数字后缀上序数词词尾。
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <vector>#include <set>#include <stack>#include <map>#include <climits>using namespace std;#define LL long longconst int INF=0x3f3f3f3f;int main(){ int t; scanf("%d",&t); while(t--) { char ch[100]; scanf("%s",ch); int len=strlen(ch); if(len==1) { if(ch[0]=='1') printf("%sst/n",ch); else if(ch[0]=='2') printf("%snd/n",ch); else if(ch[0]=='3') printf("%srd/n",ch); else printf("%sth/n",ch); } else { if(ch[len-2]=='1') printf("%sth/n",ch); else { if(ch[len-1]=='1') printf("%sst/n",ch); else if(ch[len-1]=='2') printf("%snd/n",ch); else if(ch[len-1]=='3') printf("%srd/n",ch); else printf("%sth/n",ch); } } } return 0;}
新闻热点
疑难解答