📄 p2001.cpp
字号:
#include <iostream>#include <algorithm>#include <string>using namespace std;const int MAXN = 2001;typedef struct ans{ string s; string t;}S;typedef struct node{ string s; int index;}B;S a[MAXN];B b[MAXN];bool cmp(B a,B b){ return a.s < b.s; }int main(){ freopen("t.txt","r",stdin); freopen("r.txt","w",stdout); int n(0); while(cin >> b[n].s){ a[n].s = b[n].s; b[n].index = n; ++n; } sort(b,b+n,cmp); string t; for(int i = 0;i < n;++i){ int j(0); t = ""; while(t != b[i].s){ t += b[i].s[j++]; if(i > 0 && b[i-1].s.find(t) == 0) continue; if(i < n-1 && b[i+1].s.find(t) == 0) continue; break; } b[i].s = t; a[b[i].index].t = b[i].s; } for(int i = 0;i < n;++i) cout << a[i].s << " " << a[i].t << endl;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -