生活随笔
收集整理的這篇文章主要介紹了
【PAT乙级】1058 选择题 (20 分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目地址
#include<bits/stdc++.h>
using namespace std
;
const int N
=1e5+10;
int score
[N
],sum
[N
],cnt
[N
],n
,m
;
vector
<string
>ans
;
bool check(string s
,int x
)
{int k
=0;for(int i
=0;i
<s
.size();i
++){if(ans
[x
].find(s
[i
])==-1) return false;k
++;}if(k
==ans
[x
].size()) return true;else return false;
}
int main(void)
{cin
>>n
>>m
;for(int i
=0;i
<m
;i
++){int x
;cin
>>score
[i
]>>x
>>x
;string s
;for(int j
=0;j
<x
;j
++){string temp
; cin
>>temp
;s
+=temp
;}ans
.push_back(s
);}string s
; getline(cin
,s
);for(int i
=0;i
<n
;i
++){getline(cin
,s
);int k
=0;string temp
;for(int j
=0;j
<s
.size();j
++){if(s
[j
]>='a'&&s
[j
]<='z') temp
+=s
[j
];if(s
[j
]==')'){if(check(temp
,k
)) sum
[i
]+=score
[k
];else cnt
[k
]++;k
++;temp
.clear();}}}for(int i
=0;i
<n
;i
++) cout
<<sum
[i
]<<endl
;int index
=-1;for(int i
=0;i
<m
;i
++) if(cnt
[i
]>index
) index
=cnt
[i
];if(index
){cout
<<index
;for(int i
=0;i
<m
;i
++) if(cnt
[i
]==index
) cout
<<" "<<i
+1;}else cout
<<"Too simple";return 0;
}
#include<bits/stdc++.h>
using namespace std
;
const int N
=1e5+10;
int score
[N
],sum
[N
],cnt
[N
],n
,m
;
vector
<string
>ans
;
int main(void)
{cin
>>n
>>m
;for(int i
=0;i
<m
;i
++){int x
;cin
>>score
[i
]>>x
>>x
;string s
;for(int j
=0;j
<x
;j
++){string temp
; cin
>>temp
;s
+=temp
;}ans
.push_back(s
);}string s
; getline(cin
,s
);for(int i
=0;i
<n
;i
++){getline(cin
,s
);int k
=0;string temp
;for(int j
=0;j
<s
.size();j
++){if(s
[j
]>='a'&&s
[j
]<='z') temp
+=s
[j
];if(s
[j
]==')'){if(temp
==ans
[k
]) sum
[i
]+=score
[k
]; else cnt
[k
]++;k
++;temp
.clear();}}}for(int i
=0;i
<n
;i
++) cout
<<sum
[i
]<<endl
;int index
=-1;for(int i
=0;i
<m
;i
++) if(cnt
[i
]>index
) index
=cnt
[i
];if(index
){cout
<<index
;for(int i
=0;i
<m
;i
++) if(cnt
[i
]==index
) cout
<<" "<<i
+1;}else cout
<<"Too simple";return 0;
}
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的【PAT乙级】1058 选择题 (20 分)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。