栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

2021-10-09 【PTA】【乙级】【题解1】

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021-10-09 【PTA】【乙级】【题解1】

【有问题评论区留言】 1028 人口普查 (20 分)
#include 
using namespace std;
//1028 人口普查 (20 分)
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
using namespace std;
//1022 D进制的A+B (20 分)
#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 
using namespace std;
//1023 组个最小数 (20 分)
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
using namespace std;
//1033 旧键盘打字 (20 分)

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
using namespace std;
//1040 有几个PAT (25 分)
#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;
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/302816.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号