U438634 T3 神奇的字典样例过爆零
  • 板块题目总版
  • 楼主eshXingXie
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/12/6 23:16
  • 上次更新2024/12/7 10:20:51
查看原帖
U438634 T3 神奇的字典样例过爆零
1556268
eshXingXie楼主2024/12/6 23:16

如题
代码:

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;

struct node{
	string str;
	int index;
};
bool cmp(node a,node b){
	string sa = a.str,sb = b.str;
	int i = 0;
	while(sa[i]==sb[i]){
		i++;
		if (i==sa.length()) return true;
		if (i==sb.length()) return false;
	}
	return sa[i]<=sb[i];
}
int main(){
	int n,m;
	cin>>n>>m;
	node dict[n];
	for (int i = 0;i<n;i++){
		cin>>dict[i].str;
		dict[i].index = i;
	}
	sort(dict,dict+n,cmp);
	while(m--){
		string s;
		int k;
		cin>>k>>s;
		int l = 0;
		while(dict[l].str.find_first_of(s)!=0) l++;
		if (dict[l+k-1].str.find_first_of(s)==0){
			cout<<dict[l+k-1].index+1<<"\n";
		}
		else {
			cout<<"-1\n";
		}
	}
	return 0;
}
2024/12/6 23:16
加载中...