Roman Order&&字符串处理问题
#include<cstdio>#include<algorithm>#include<string.h>#include<iostream>#include<string>using namespace std;char strHundreds[10][5]={"C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}; char strTens[10][5]={"X","XX","XXX","XL","L","LX","LXX","LXXX","XC"}; char strOnes[10][5]={"I","II","III","IV","V","VI","VII","VIII","IX"}; char strThousands[4][4]={"M","MM","MMM"};typedef struct{char ch[20];int id;}Node;Node s[10005];int s1[10005];bool operator < (Node const& x,Node const&x1){return strcmp(x.ch,x1.ch)<0;}int main(){int T;scanf("%d",&T);while(T--){int n;scanf("%d",&n);for(int i=0;i<n;++i){int a;char temp[20]="\0";scanf("%d",&s1[i]);a=s1[i];if(a/1000){ strcat(temp,strThousands[a/1000-1]);a%=1000;}if(a/100){strcat(temp,strHundreds[a/100-1]);a%=100;}if(a/10){strcat(temp,strTens[a/10-1]);a%=10;}if(a){strcat(temp,strOnes[a-1]);}strcpy(s[i].ch,temp);s[i].id=i;memset(temp,0,sizeof(temp));}std::sort(s,s+n);for(int i=0;i<n-1;++i) printf("%d ",s1[s[i].id]);printf("%d\n",s1[s[n-1].id]);}return 0;}