一言
有情人终成眷属,没钱人亲眼目睹。——互联网
PTA刷题
本文最后更新于 580 天前,其中的信息可能已经有所发展或是发生改变。

一定要坚持下去,别像蓝桥杯一样了,哎 一定要克服懒惰。

L1-002 打印沙漏

少过一个样例,懒得调试了

#include <bits/stdc++.h>
using namespace std;
int s[25] = {1, 7, 17, 31, 49, 71, 97, 127, 161, 199, 241, 287, 337, 391, 449, 511, 577, 647, 721, 799, 881, 967};
int main()
{
    int n;
    char word;
    cin >> n >> word;
    int t, tindex = 0;
    for (int i = 0; i < 23; i++)
    {
        if (n >= s[21])
        {
            t = s[i];
            tindex = 21;
            // cout << t;
            break;
        }
        if (n >= s[i] && n < s[i + 1])
        {
            t = s[i];
            tindex = i;
            // cout << t;
            break;
        }
    }
    int maxx = (tindex + 1) * 2 - 1;
    int max2 = (tindex + 1) * 2 - 1;
    int spacenum = 0;
    for (int i = 1; i <= maxx; i++)
    {
        // cout << spacenum << max2;
        if (i <= tindex)
        {
            for (int k = 0; k < spacenum; k++)
                printf(" ");
            for (int j = 1; j <= max2; j++)
                printf("%c", word);
            puts("");
            spacenum++;
            max2 -= 2;
        }
        else
        {
            for (int k = 0; k < spacenum; k++)
                printf(" ");
            for (int j = 1; j <= max2; j++)
                printf("%c", word);
            puts("");
            spacenum--;
            max2 += 2;
        }
    }
    cout << n - t;

    return 0;
}

L1-003 个位数统计

n = input()
l = {}
for i in n:
    if i not in l:
        l[i] = 1
    else:
        l[i] += 1
l = sorted(l.items())
# print(l)
for i in l:
    print("{}:{}".format(i[0], i[1]))

L1-005 考试座位号

#include <bits/stdc++.h>
using namespace std;
struct node
{
    long long id;
    int one;
    int two;
} a[1007];
int main()
{
    int x[1007];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].id >> a[i].one >> a[i].two;
    }
    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        cin >> x[i];
    }
    for (int i = 0; i < t; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (x[i] == a[j].one)
            {
                printf("%lld %d", a[j].id, a[j].two);
                puts("");
                break;
            }
        }
    }
    return 0;
}

L1-009 N个数求和

一开始竟然有转化成小数做的冲动。。。。。

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
struct node
{
    int zi;
    int mu;
} a[1000], ans;
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        scanf("%d/%d", &a[i].zi, &a[i].mu);
    ans = a[0];
    for (int i = 1; i < n; i++)
    {
        ans.zi = ans.zi * a[i].mu + a[i].zi * ans.mu;
        ans.mu *= a[i].mu;

        int g = gcd(ans.zi, ans.mu);
        if (g != 1)
        {
            ans.zi /= g;
            ans.mu /= g;
        }
    }
    // cout << ans.zi << " " << ans.mu;

    int z = ans.zi / ans.mu;
    int f = ans.zi % ans.mu;
    if (z != 0 && f != 0)
        cout << z << " " << f << "/" << ans.mu;
    else if (z == 0 && f == 0)
        cout << 0;
    else if (z != 0 && f == 0)
        cout << z;
    else if (z == 0 && f != 0)
        cout << f << "/" << ans.mu;

    return 0;
}

L1-011 A-B

a = input()
b = input()
for i in a:
    if i not in b:
        print(i, end="")

L1-015 跟奥巴马一起画方块

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
struct node
{
    int zi;
    int mu;
} a[1000], ans;
int main()
{
    int n, n2;
    char c;
    cin >> n >> c;
    n2 = n;
    if (n & 1)
        n = n / 2 + 1;
    else
        n /= 2;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n2; j++)
        {
            cout << c;
        }
        puts("");
    }

    return 0;
}

L1-016 查验身份证
明明都是些简单题,但是我总是会出些奇奇怪怪的bug我真是太久没刷题了

n = int(input())
l = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
d = {0: '1', 1: "0", 2: 'X', 3: "9", 4: "8",
     5: "7", 6: "6", 7: "5", 8: "4", 9: "3", 10: "2"}
ans = []
sum = 0
flag = False
for i in range(n):
    sum = 0
    flag = False
    t = input()
    for i in range(17):
        if t[i] < '0' or t[i] > '9':
            ans.append(t)
            flag = True
            break
    if flag == True:
        continue
    for i in range(17):
        sum += int(t[i])*l[i]
        # print("{}*{}={}".format(int(t[i]), l[i], int(t[i])*l[i]), end=" ")
        # print(sum)
    index = sum % 11
    # print(index)
    if d[index] != t[17]:
        ans.append(t)
if ans:
    for i in ans:
        print(i)
else:
    print("All passed")

L1-023 输出GPLT

#include<bits/stdc++.h>
using namespace std;
int x[100000];
int main()
{
    string a;
    cin>>a;
    for(char i:a)
    {
//         cout<<i<<" ";
        x[i]++;
    }
    x['G']+=x['g'];
    x['P']+=x['p'];
    x['L']+=x['l'];
    x['T']+=x['t'];
    char t[4]={'G','P','L','T'};
//     cout<<x['G']<<x['P']<<x['L']<<x['T'];
    while(true)
    {
        for(char i:t)
        {
            if(x[i]>0)
            {
                cout<<i;
                x[i]--;
            }

        }
        if(x['G']==0&&x['P']==0&&x['L']==0&&x['T']==0)break;
    }

}

L1-017 到底有多二

n=input()
sum=1
l=0
if n[0]=='-':
    sum*=1.5
    l=len(n)-1
if int(n)%2==0:
    sum*=2
if n[0]!='-':
    l=len(n)
num=0
for i in n:
    if i=='2':
        num+=1
print("{:.2f}%".format(float(num)/l*sum*100))

L2-002 链表去重
只过了15分/(ㄒoㄒ)/~~ 呜呜呜
l2 有点东西 难不成让我真写一个链表
白瞎我写那么长时间

#include <bits/stdc++.h>
using namespace std;
struct node
{
    int val;
    int next;
};
const int N = 10000000;
struct node a[N];
struct node b[N];
int x[N];
int main()
{
    int head, n;
    cin >> head >> n;
    for (int i = 0; i < n; i++)
    {
        int ad, va, ne;
        cin >> ad >> va >> ne;
        a[ad].val = va;
        a[ad].next = ne;
    }
    int idx = head;
    int head2=-1;    // 链表b的头结点
    int flag = 0; // 0表示b链表还为空
    int temp;
    int t = 0; // 被删除节点的个数
    while(idx!=-1)
    {
        x[abs(a[idx].val)] = 1;
        if (x[abs(a[a[idx].next].val)] != 0) // 这个if里的a[idx].next指的是被删除节点的地址
        {
            if (flag == 0) // 第一个被删除的节点,作为b链表的头结点
            {
                head2 = a[idx].next;
                b[a[idx].next].val = a[a[idx].next].val;
                b[a[idx].next].next = -1; // 他是头结点,next先指向空
                temp = head2;             // 标记指针用来尾插
                flag = 1;
            }
            else
            {
                b[a[idx].next].val = a[a[idx].next].val;
                b[temp].next = a[idx].next;
                temp = a[idx].next;
                b[temp].next=-1;
            }
            t++;
            a[idx].next = a[a[idx].next].next; // 删除节点
        }
//          cout << idx << " " << a[idx].val << " " << a[idx].next<<endl;

        idx = a[idx].next;
    }
    idx = head;
    while(idx!=-1)
    {
          if(a[idx].next!=-1)
         {
              printf("%05d %d %05d\n",idx,a[idx].val,a[idx].next);
         }
         else{
             printf("%05d %d -1\n",idx,a[idx].val);
         }
//         cout << idx << " " << a[idx].val << " " << a[idx].next << endl;
        idx = a[idx].next;
    }
    if(head2!=-1)
    {
    idx=head2;
    while(idx!=-1)
    {
         if(b[idx].next!=-1)
         {
              printf("%05d %d %05d\n",idx,b[idx].val,b[idx].next);
         }
         else{
             printf("%05d %d -1\n",idx,b[idx].val);
         }

//         cout << idx << " " << b[idx].val << " " << b[idx].next << endl;
        idx = b[idx].next;
    }
    }

}
暂无评论

发送评论 编辑评论

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇