天梯赛刷题小记 —— L1

最近在重刷 天梯赛,浅浅记录一下,就不管简易程度了

感觉已经很久没有做题了qaq


L1-002 打印沙漏

解题思路:循环结构
AC代码:

#include <bits/stdc++.h>
#define inf 0x3f3f3f
using namespace std;
const int N = 1e3+10;
int cot[N], cot2[N];
int cotsize = 0;
void init(){
    cot[0] = 1;
    int x = 1;
    cot2[0] = x;
    for(int i = 1; i<=100 && cot[i-1]<=1000; i++){
        cot[i] = cot[i-1] + (x +2) *2;
        x += 2;
        cot2[i] = x;
        cotsize++;
        //cout<<cot[i]<<' ';
    }
}
signed main()
{
    int n;
    char ch;
    
    cin>>n>>ch;
    init();
    int pos = 0;
    for(int i=0; i<cotsize+1; i++){
        if(n < cot[i]){
            pos = i-1; break;
        }
    }
    int x = 0;
    for(int i = cot2[pos]; i>0; i-= 2){
        for(int j = 0; j<cot2[pos] - i; j+=2) cout<<' ';
        for(int j = 0; j<i; j++) cout<<ch;
        cout<<endl;
    }
    if(n >= 7 ){
        for(int i = 3; i<=cot2[pos]; i+= 2){
            for(int j = 0; j<cot2[pos] - i; j+=2) cout<<' ';
            for(int j = 0; j<i; j++) cout<<ch;
            cout<<endl;
        }
    }
    cout<<n - cot[pos]<<endl;
    return 0;
}

L1-003 个位数统计

解题思路:字符串遍历计数。

L1-004 计算摄氏温度

解题思路:浮点数与整数

L1-005 考试座位号

解题思路:简单映射

L1-006 连续因子

解题思路:暴力枚举

注意点:输出格式要注意,有一些傻叉一样的格式问题。

还有一点就是要的是最小的连续因子序列

AC代码:

#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int N = 1e3+10;

signed main()
{
  int n;
    cin>>n;
    int len= 0 , begin = 0;
    for(int i = 2; i * i < n + 1; i++){
        if(n % i ) continue;
        else{
            int x = n;
            int cot = 0;
            for(int j=i; x % j == 0; j++){
                cot++;
                x /= j;
            }
            if(cot > len) len = cot, begin = i;
        }
    }
    if (len == 0) {
		cout << '1' << endl << n;
	} else {
		cout << len << endl;
		for (int i = 0; i < len; i++) {
			if (i == 0) {
				cout <<begin + i;
			} else {
				cout << '*' <<begin + i;
			}
		}
	}
        
    return 0;
}

L1-007 念数字

解题思路:简单映射

L1-008 求整数段和

解题思路:格式化输出

L1-009 N个数求和

解题思路:最大公约数

// 已知 要求 最小公倍数 !
// 或者直接相乘,最后分子分母求一下 最大公约数,然后除一下

#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[110];
int gcd(int a, int b)
{
    // 原理 辗转相除法
    return b ? gcd(b, a % b) : a;
}
int main()
{
    int n;
    scanf("%d", &n
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值