个人赛9
作者:互联网
B
#include <iostream> #include <algorithm> #include <cstring> #include <math.h> using namespace std; typedef long long ll; const int N=1e3+10; char s[30]; int num[30]; string a[N]; string tmp; signed main() { cin>>s; for (int i=0; i<26; i++) { int ver=s[i]-'a'+1; num[ver]=i+1; } int n; scanf("%d",&n); for (int i=0; i<n; i++) { cin>>a[i]; } for (int i=0; i<n-1; i++) { int len1=a[i].size(); for (int j=i+1; j<n; j++) { int len2=a[j].size(); int k=0; int len=min(len1,len2); while (k<len) { if (num[a[i][k]-'a'+1]>num[a[j][k]-'a'+1]) { tmp=a[i]; a[i]=a[j]; a[j]=tmp; break; } else if (num[a[i][k]-'a'+1]<num[a[j][k]-'a'+1])//孩子哭了,没看清题,少了这一步,连wa3遍。 { break; } k++; } if (k==len&&len1>len2) { tmp=a[i]; a[i]=a[j]; a[j]=tmp; } } } int w; scanf("%d",&w); cout<<a[w-1]<<"\n"; return 0; }
标签:tmp,string,int,long,num,个人赛,include 来源: https://www.cnblogs.com/Mercury1988/p/16333092.html