跳到正文

个人记录

8.15课堂总结

MCminecrnft约 7 分钟
原文
文章信息与版本

文章信息

发布
2026年8月15日
收录
2026年8月16日
更新
2026年11月14日
篇幅
约 7 分钟

版本

  1. v1当前

T4 T805942 T4

1.题意:求a到b的所有数中,有多少个“幸运数(0,1,2…n-1(n为数字的位数)”

2.思路:用函数,先拆数,再算数位,接着用tong来计数,最后再判断tong是不是等于1即可

3.AC代码:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int f(int x)
{
    int tong[15] = {};
    int ans = 0;
    while(x)
    {
        tong[x%10]++;
        x/=10;
        ans++;
    }
    for(int i = 0;i<ans;i++)
    {
        if(tong[i] == 0)   return 0;
    }
    return 1;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int a,b;
    cin>>a>>b;
    int cnt = 0;
    for(int i = a;i<=b;i++)
    {
        cnt += f(i);
    }
    cout<<cnt;
	return 0;
} 

4.错因:都在主函数里写的,导致错了没法改。

T5 T805943 T5

1.题意:先输入一个n,m,再根据op来判断,如果为1,则将x行和y行交换一下位置,否则,将x列和y列交换一下位置。

2.思路:可以定义两个数组来存行和列,输出是再通过映射来输出。

3.AC代码:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int a[1005][1005];
int h[1005],l[1005];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i = 1;i<=n;i++)
    {
        for(int j = 1;j<=n;j++)
        {
            cin>>a[i][j];
            h[j] = j;
        }
        l[i] = i;
    }
    for(int i = 1;i<=m;i++)
    {
        int op,x,y;
        cin>>op>>x>>y;
        if(op == 1)   
        {
            swap(h[x],h[y]);
        }
        if(op == 0)
        { 
            swap(l[x],l[y]);
        }
    }
    for(int i = 1;i<=n;i++)
    {
        for(int j = 1;j<=n;j++)
        {
            cout<<a[h[i]][l[j]]<<" ";
        }
        cout<<endl;
    }
	return 0;
} 

4.错因:没想到可以用映射来写,只是用数组直接来改,继超时有WA,还不会改。

T6 T805944 T6

1.题意:输入4行字符串,输出A-Z的柱状图。

2.思路:先通过循环嵌套来输入和找最大值,接着for循环来遍历判断如果tong[j]>=i,输出* ,否则输出 。最后输出A-Z。

3.AC代码:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int tong[155];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int maxn = 0;
    for(int i = 1;i<=4;i++)
    {
        string s;
        getline(cin,s);
        for(int j = 0;j<s.size();j++)
        {
            tong[s[j]]++;
            if(s[j]>='A'&&s[j]<='Z')
            {
                 maxn = max(maxn,tong[s[j]]);
            }
    	}
    }
    for(int i = maxn;i>=1;i--)//
    {
    	for(int j = 'A';j<='Z';j++)
    	{
    		if(tong[j] >= i)  cout<<"* ";
        	else  cout<<"  ";	
		}
        cout<<endl;
    }
    cout<<"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z";
	return 0;
} 

4.错因:题虽然看懂了,但完全不知道如何下手

T7 T805946 T7

1.题意:先输入n,x,接着求获奖的最低分数,最后求有多少人获奖,输出获奖的分数。

2.思路:先求分数,接着从600-0依次遍历,如果cnt>=fs,输出j,然后break;

3.AC代码:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int tong[605];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int n,w;
    cin>>n>>w;
    for(int i = 1;i<=n;i++)
    {
        int x;
        cin>>x;
        tong[x]++;
        int fs = max(1ll,i*w/100);
        int cnt = 0;
        for(int j = 600;j>=0;j--)
        {
           cnt += tong[j];
           if(cnt >= fs)   
           {
               cout<<j<<" ";
               break;
           }
        }
    }
	return 0;
} 

4.错因:写了一会,但因为思路不清晰,导致一直在折腾,后面又不知道了。

原文