头像

hollo_night_lyc


访客:4576

离线:5小时前


活动打卡代码 AcWing 462. 扫雷游戏

//丹阳新区实小路彦
#include <bits/stdc++.h>
using namespace std;

const int N = 110;
int n, m;
char g[N][N];

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> g[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
            if (g[i][j] == '*') cout << '*';
            else
            {
                int s = 0;
                for (int x = i - 1; x <= i + 1; x++)
                    for (int y = j - 1; y <= j + 1; y++)
                        if (x != i || y != j)
                        {
                            if (x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '*') s ++ ;
                        }
                cout << s;
            }
        cout << endl;
    }
    return 0;
}



//丹阳新区实小路彦
#include <bits/stdc++.h>
using namespace std;

const int N = 110;
int n, m;
char g[N][N];

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> g[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
            if (g[i][j] == '*') cout << '*';
            else
            {
                int s = 0;
                for (int x = i - 1; x <= i + 1; x++)
                    for (int y = j - 1; y <= j + 1; y++)
                        if (x != i || y != j)
                        {
                            if (x >= 0 && x < n && y >= 0 && y < m && g[x][y] == '*') s ++ ;
                        }
                cout << s;
            }
        cout << endl;
    }
    return 0;
}


活动打卡代码 AcWing 441. 数字统计

//丹阳新区实小路彦
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int l, r;
    cin >> l >> r;
    int res = 0; 
    for (int i = l; i <= r; i ++ )
        for (int j = i; j; j /= 10)
            if (j % 10 == 2) res++;
    cout << res << endl;
    return 0;
}



//丹阳新区实小路彦
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int l, r;
    cin >> l >> r;
    int res = 0; 
    for (int i = l; i <= r; i ++ )
        for (int j = i; j; j /= 10)
            if (j % 10 == 2) res++;
    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 437. 多项式输出

//丹阳新区实小路彦
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n, a;
    cin >> n;
    for(int i = n; i >= 0; i--)
    {
        cin >> a;
        if(a)
        {
            if(i != n && a > 0) cout << "+"; 
            if(abs(a) > 1 || i == 0) cout << a; 
            if(a == -1 && i) cout << "-";
            if(i > 1) cout << "x^" << i;
            if(i == 1) cout << "x";
        }
    }
}



//丹阳新区实小路彦
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n, a;
    cin >> n;
    for(int i = n; i >= 0; i--)
    {
        cin >> a;
        if(a)
        {
            if(i != n && a > 0) cout << "+"; 
            if(abs(a) > 1 || i == 0) cout << a; 
            if(a == -1 && i) cout << "-";
            if(i > 1) cout << "x^" << i;
            if(i == 1) cout << "x";
        }
    }
}


活动打卡代码 AcWing 429. 奖学金

//丹阳新区实小路彦
#include <bits/stdc++.h>
using namespace std;

struct node
{
    int cn, id, sum;
} stu[305];

bool cmp(node a, node b)
{
    if (a.sum == b.sum)
    {
        if (a.cn == b.cn) return a.id < b.id;
        else return a.cn > b.cn;
    }
    else return a.sum > b.sum;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        stu[i].id = i;
        stu[i].sum = x + y + z;
        stu[i].cn = x;
    }
    sort(stu + 1, stu + n + 1, cmp);
    for (int i = 1; i <= 5; i++)
        cout << stu[i].id << " " << stu[i].sum << endl;
    return 0;
}



//丹阳新区实小路彦
#include <bits/stdc++.h>
using namespace std;

struct node
{
    int cn, id, sum;
} stu[305];

bool cmp(node a, node b)
{
    if (a.sum == b.sum)
    {
        if (a.cn == b.cn) return a.id < b.id;
        else return a.cn > b.cn;
    }
    else return a.sum > b.sum;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        stu[i].id = i;
        stu[i].sum = x + y + z;
        stu[i].cn = x;
    }
    sort(stu + 1, stu + n + 1, cmp);
    for (int i = 1; i <= 5; i++)
        cout << stu[i].id << " " << stu[i].sum << endl;
    return 0;
}


活动打卡代码 AcWing 445. 数字反转

//丹阳新区实小路彦
#include <bits/stdc++.h>
using namespace std;

int main()
{
    string a;
    cin >> a;
    reverse(a.begin(), a.end());
    int i = 0;
    while (a.size() != i)
    {
        if (a[i] == '-')
        {
           cout << '-';
           a[i] = ' ';
        }
        i++;
    }
    i = 0;
    while (i + 1 < a.size() && a[i] == '0')
        i++;
    while (i < a.size())
        cout << a[i++];
}



//丹阳新区实小路彦
#include <bits/stdc++.h>
using namespace std;

int main()
{
    string a;
    cin >> a;
    reverse(a.begin(), a.end());
    int i = 0;
    while (a.size() != i)
    {
        if (a[i] == '-')
        {
           cout << '-';
           a[i] = ' ';
        }
        i++;
    }
    i = 0;
    while (i + 1 < a.size() && a[i] == '0')
        i++;
    while (i < a.size())
        cout << a[i++];
}