3601. 恢复古诗

IWani-Z

https://blog.csdn.net/IWani_Z/article/details/105107988

CCXXXI_

从统计数据来看,这堆东西跑起来竟然能比多数cpp答案快,奇妙

p, l = map(int, input().split())
if l == 1:
    print(input())
    exit()
d, e = dict(), set()
for i in range(p):
    t = [input() for j in range(l)]
    d[t[0]] = t
    e.add(t[-1])
h = (set(d) - e).pop()
print(d[h][0])
while h in d:
    t = d[h]
    print(*t[1:], sep='\n')
    h = t[-1]
Cuibaby

text5 runtime了

include

include

using namespace std;
struct g {
string s[101];
} G[1001];
mapm,m1;
int main() {
int t,l;
cin>>t>>l;
int index;
getchar();
for(int i = 1; i <= t; i++) {
for(int j =1 ; j <= l; j++) {
getline(cin,G[i].s[j]);
}
m[G[i].s[1]]++;
m[G[i].s[l]]++;
m1[G[i].s[1]]=i;
}//找第一个节点
for(map::iterator it = m.begin(); it!=m.end(); it++) {
if(it->second==1) {
if(m1[it->first]) {
index=m1[it->first];
// cout<<index;
break;
}
}
}
int count=1;
for(int j= 1; j<=l; j++)
cout<<G[index].s[j]<<endl;
string s=G[index].s[l];
while(count<t) {
s=G[index].s[l];
for(int i = 1; i <= t; i++) {
if(s==G[i].s[1]) {
index=i;
break;
}
}
for(int j= 2; j<=l; j++)
cout<<G[index].s[j]<<endl;
count++;
}
return 0;
}

你当前正在回复 博客/题目
存在问题!