团体程序设计天梯赛-练习集L1

 

 

目录

L1-002 打印沙漏  

L1-003 个位数统计

L1-006 连续因子 

L1-009 N个数求和

L1-011 A-B

L1-020 帅到没朋友

L1-023 输出GPLT 

L1-027 出租

L1-043 阅览室

L1-049 天梯赛座位分配

L1-056 猜数字


L1-002 打印沙漏  

先判断层数,对半处理

#include<cstdio>
char map[10][10];

int main(){
	int n;char c;
	while(~scanf("%d %c",&n,&c)){
		int i,cnt=1,num=1;
		for(i=3;;i+=2){
			if(num+2*i>n) break;
			num+=2*i;
			cnt++;
		}
		i-=2;
		int res=n-num;
		//printf("%d\n",num);
		//printf("%d--%d\n",i,cnt);
		for(int j=0;j<cnt;j++){
			int cmp=j;
			while(cmp--) printf(" ");
			for(int k=0;k<i-2*j;k++){
				printf("%c",c);
			}
			printf("\n");
		}
		for(int j=cnt-2;j>=0;j--){
			int cmp=j;
			while(cmp--) printf(" ");
			for(int k=0;k<i-2*j;k++){
				printf("%c",c);
			}
			printf("\n");
		}
		printf("%d\n",res);
	}
	return 0;
}

L1-003 个位数统计

map使用

#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
using namespace std;
map<char,int>v;

int main(){
	char s[1005];
	cin.getline(s,1005);
	for(int i=0;i<strlen(s);i++)
		v[s[i]]++;
		
	map<char,int>::iterator it;
	for(it=v.begin();it!=v.end();it++){
		printf("%c:%d\n",it->first,it->second);
	}
	return 0;
}

L1-006 连续因子 

暴力求

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;


int main(){
	int n;
	while(~scanf("%d",&n)){
		int len=0,st=0;
		for(int i=2;i<=(int)sqrt(n);i++){
			ll tmp=1;
			for(int j=i;j*tmp<=n;j++){
				tmp*=j;
				if(n%tmp==0&&j-i+1>len){
					st=i;
					len=j-i+1;
				} 
			}
		}
		if(st==0) st=n,len=1;
		printf("%d\n%d",len,st);
		for(int i=st+1;i<st+len;i++)
			printf("*%d",i);
		printf("\n");
	}
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值