【有问题评论区留言】
1028 人口普查 (20 分)
#include <iostream>
using namespace std;
int main() {
int n, cnt = 0;
cin >> n;
string name, birth, maxname, minname, maxbirth = "1814/09/06", minbirth = "2014/09/06";
for (int i = 0; i < n; i++) {
cin >> name >> birth;
if (birth >= "1814/09/06" && birth <= "2014/09/06") {
cnt++;
if (birth >= maxbirth) {
maxbirth = birth;
maxname = name;
}
if (birth <= minbirth) {
minbirth = birth;
minname = name;
}
}
}
cout << cnt;
if (cnt != 0) cout << " " << minname << " " << maxname;
return 0;
}
1022 D进制的A+B (20 分)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(0);
ll a,b,d;
cin >> a >> b>>d;
ll c=a+b;
if (c == 0) {
cout << 0;
return 0;
}
ll arr[100] = {
0}, i = 0;
while(c){
arr[i++] = c % d;
c /= d;
}
for (ll j = i - 1; j >= 0;j--){
cout << arr[j];
}
return 0;
}
1023 组个最小数 (20 分)
#include <iostream>
using namespace std;
int main() {
int a[10], t;
for (int i = 0; i < 10; i++)
cin >> a[i];
for (int i = 1; i < 10; i++) {
if (a[i] != 0) {
cout << i;
t = i;
break;
}
}
for (int i = 0; i < a[0]; i++) cout << 0;
for (int i = 0; i < a[t] - 1; i++) cout << t;
for (int i = t + 1; i < 10; i++)
for (int k = 0; k < a[i]; k++)
cout << i;
return 0;
}
1033 旧键盘打字 (20 分)
#include<bits/stdc++.h>
using namespace std;
int main() {
string bad, should;
getline(cin, bad);
getline(cin, should);
for (int i = 0, length = should.length(); i < length; i++) {
if (bad.find(toupper(should[i])) != string::npos) continue;
if (isupper(should[i]) && bad.find('+') != string::npos) continue;
cout << should[i];
}
return 0;
}
1040 有几个PAT (25 分)
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main(){
ios::sync_with_stdio(0);
string s;
cin>>s;
int len = s.size();
int ans = 0, cntp = 0, cntt = 0;
for (int i = 0; i < len;i++){
if(s[i]=='T')
cntt++;
}
for (int i = 0; i < len;i++){
if(s[i]=='P')
cntp++;
if(s[i]=='T')
cntt--;
if(s[i]=='A')
ans = (ans + (cntp * cntt) % mod) % mod;
}
cout << ans;
return 0;
}