题意:为第几加后缀。
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3487
——>>直接模拟。
#include <iostream>
using namespace std;
int main()
{
int T, n;
cin>>T;
while(T--)
{
cin>>n;
int tens = n % 100 / 10;
int ones = n % 10;
cout<<n;
if(tens != 1)
{
switch(ones)
{
case 1:
{
cout<<"st"<<endl;
break;
}
case 2:
{
cout<<"nd"<<endl;
break;
}
case 3:
{
cout<<"rd"<<endl;
break;
}
default:
{
cout<<"th"<<endl;
break;
}
}
}
else cout<<"th"<<endl;
}
return 0;
}
本文介绍了一个简单的C++程序,该程序用于给输入的整数添加对应的英文数序后缀,如1st, 2nd, 3rd等,并通过switch-case结构实现了对不同情况的判断。
527

被折叠的 条评论
为什么被折叠?



