知識
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!
PTA家譜處理c++版——山東科技大學(xué)
發(fā)表時間:2020-10-17
發(fā)布人:葵宇科技
瀏覽次數(shù):86
輸入:
6 5
John
Robert
Frank
Andrew
Nancy
David
Robert is a child of John
Robert is an ancestor of Andrew
Robert is a sibling of Nancy
Nancy is the parent of Frank
John is a descendant of Andrew
輸出:
True
True
True
False
False
//第一次寫,無注釋。
#include<bits/stdc++.h>
using namespace std;
struct People
{
string name;
int write;
int parent;
} people[105];
map<string,int>mp;
int n,m;
void init()
{
cin>>n>>m;
string ss,s;
int len,x=0;
cin>>people[0].name;
people[0].parent=-1;
people[0].write=0;
getchar();
for(int i=1; i<n; i++)
{
x=0;
getline(cin,ss);
len=ss.length();
for(int j=0; j<len; j++)
{
if(ss[j]!=' ')
break;
x++;
}
people[i].name=ss.substr(x,len-x);
people[i].write=x;
mp[people[i].name]=i;
for(int j=i-1; j>=0; j--)
{
if(people[i].write==people[j].write)
{
people[i].parent=people[j].parent;
break;
}
if(people[i].write==people[j].write+2)
{
people[i].parent=j;
break;
}
}
}
}
bool find(int a,int b)
{
if(people[a].parent==b)
return true;
return a==0?false:find(people[a].parent,b);
}
bool judge(string s1,string relation,string s2)
{
switch (relation[0])
{
case 'c':
{
if(people[mp[s1]].parent==mp[s2])
return true;
break;
}
case 'p':
{
if(people[mp[s2]].parent==mp[s1])
return true;
break;
}
case 's':
{
if(people[mp[s1]].parent==people[mp[s2]].parent)
return true;
break;
}
case 'a':
{
if(find(mp[s2],mp[s1]))
return true;
break;
}
case 'd':
{
if(find(mp[s1],mp[s2]))
return true;
break;
}
}
return false;
}
void solve()
{
int x=0;
string s,s1,s2,r;
for(int i=0; i<m; i++)
{
x=0;
getline(cin,s);
stringstream ss;
ss<<s;
while(ss>>s)
{
x++;
if(x==1)
s1=s;
if(x==6)
s2=s;
if(x==4)
r=s;
}
if(judge(s1,r,s2))
cout<<"True"<<endl;
else
cout<<"False"<<endl;
}
}
int main()
{
//freopen("in.txt","r",stdin);
init();
solve();
return 0;
}
每天進(jìn)步一點(diǎn)點(diǎn),十天進(jìn)步十點(diǎn)點(diǎn),加油!
更多PTA作業(yè)代碼都在我的博客中
ps:答案僅供參考,請勿抄襲
相關(guān)案例查看更多
相關(guān)閱讀
- 網(wǎng)站優(yōu)化公司
- 做網(wǎng)站
- 云南小程序定制
- 搜索排名
- 大理網(wǎng)站建設(shè)公司
- 云南網(wǎng)站設(shè)計
- 汽車回收管理
- 正規(guī)網(wǎng)站建設(shè)公司
- 云南軟件公司
- 網(wǎng)站建設(shè)首頁
- 百度推廣
- web開發(fā)
- 網(wǎng)站排名優(yōu)化
- 江蘇小程序開發(fā)
- 云南網(wǎng)站建設(shè)開發(fā)
- 云南網(wǎng)站建設(shè)快速優(yōu)化
- 網(wǎng)站建設(shè)特性
- 小程序分銷商城
- 搜索引擎排名
- 關(guān)鍵詞快速排名
- 昆明軟件定制公司
- 云南網(wǎng)站建設(shè)公司排名
- 云南小程序設(shè)計
- 云南小程序開發(fā)課程
- 二叉樹
- 汽車拆解管理軟件
- 百度排名
- 云南網(wǎng)站建設(shè)服務(wù)
- 南通小程序制作公司
- 汽車報廢回收軟件