题意:给n个号码,求出每个号码最短的能唯一定位该号码的字符串
思路:暴力 把每个号码的子串放进map里,然后从长度短的开始暴力每一个子串出现的次数,出现一次的就是能定位的,同一个号码里的相同子串只记录一次,如0000 ,子串000出现2次,但是只记录一次(当然也可以字典树或者后缀数组写拉,但是暴力是坠吼滴
AC代码:
#include "iostream"#include "iomanip"#include "string.h"#include "stack"#include "queue"#include "string"#include "vector"#include "set"#include "map"#include "algorithm"#include "stdio.h"#include "math.h"#pragma comment(linker, "/STACK:102400000,102400000")#define bug(x) cout<<<" "<<"UUUUU"< M,m[70002];int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n; cin>>n; for(int i=1; i<=n; ++i){ cin>>s[i]; } for(int i=1; i<=n; ++i){ for(int j=0; j<9; ++j){ for(int k=1; k+j<=9; ++k){ string ss=s[i].substr(j, k); if(!m[i][ss]){ m[i][ss]++; M[ss]++; } } } } for(int i=1; i<=n; ++i){ int flag=0; for(int k=1; k<=9; ++k){ for(int j=0; j+k<=9; ++j){ string ss=s[i].substr(j, k); if(M[ss]==1){ cout< <