Run ID:75828

提交时间:2024-05-30 18:42:32

#include<iostream> #include<string> using namespace std; int main() { int n,b[101],s=0; cin>>n; string str[n],t; int i,j; for (i = 0; i < n; i++) cin >> str[i]; for(i=0;i<n-1;i++) for(j=0;j<n-1-i;j++) if (str[j].size() > str[j + 1].size()) { t = str[j]; str[j] = str[j + 1]; str[j + 1] = t; } for(i=0;i<n-1;i++) for(j=0;j<n-1-i;j++) if (str[j].size()==str[j + 1].size()&&str[j]>str[j+1]) { t = str[j]; str[j] = str[j + 1]; str[j + 1] = t; } for(i=0;i<n;i++) if (str[i].size()==str[i-1].size()){ b[i]=s; } else{ s++; b[i]=s; } for (i=n-1; i>=0; i--) cout<<b[i]<<" "<<str[i]<<endl; return 0; }