天梯赛 1.31

本文展示了几个C语言编程示例,包括猜数字游戏、字符串翻转、敲笨钟检测和心理阴影面积计算,以及与蓝桥杯竞赛相关的幸运数计算。
摘要由CSDN通过智能技术生成

L1-056 猜数字

#include <stdio.h>
struct stu
{
	char name[24];
	int number;
}ss[10005];
int main()
{
	int n,sum=0,ave,t;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%s %d",&ss[i].name,&ss[i].number);
	}
	for(int i=0;i<n;i++)
	{
		sum+=ss[i].number;
	}
	ave=sum/n/2;
	int t1,t2;
	t1=abs(ss[0].number-ave);
	for(int i=1;i<n;i++)
	{
		t2=abs(ss[i].number-ave);
		if(t1>t2)
		{
			t1=t2;
			t=i;
		}
	}
	printf("%d %s",ave,ss[t].name);
	return 0;
}

L1-057 PTA使我精神焕发

#include <stdio.h>
int main()
{
    printf("PTA shi3 wo3 jing1 shen2 huan4 fa1 !");
    return 0;
}

 L1-058 6翻了

#include<stdio.h>
#include<string.h>
int main()
{
    char str[1005];
    int count = 0, i, j;
    gets(str);
    for (i = 0; i <= strlen(str); i++)
    {
        if (str[i] == '6')
        {
            count++;
        }
        else
        {
            if (count > 9)
                printf("27");
            else if (count > 3)
                printf("9");
            else
            {
                for (j = 0; j < count; j++)
                {
                    printf("6");
                }
            }
            printf("%c", str[i]);
            count = 0;
        }
    }
    return 0;
}

 L1-059 敲笨钟

#include <stdio.h>
#include <string.h>
int main(){
	int n,i,j;
	int len,flagA,flagB;
	int count,pos;
	char s[101];
	scanf("%d",&n);
	getchar();	//接收回车字符 
	for(i=0;i<n;i++){
		len=0,flagA=0,flagB=0,count=0;
		gets(s);
		len=strlen(s);
		for(j=0;j<len;j++){
			if(s[j]==','&&s[j-3]=='o'&&s[j-2]=='n'&&s[j-1]=='g')
				flagA=1;
			if(s[j]=='.'&&s[j-3]=='o'&&s[j-2]=='n'&&s[j-1]=='g')
				flagB=1;
		}
		if(flagA==1&&flagB==1){
			for(j=len-1;j>=0;j--){
				if(s[j]==' ')
					count++;
				if(count==3){
					pos=j;
					break;
				}
			}
			for(j=0;j<=pos;j++){
				printf("%c",s[j]);
			}
			printf("qiao ben zhong.\n");
		}else{
			printf("Skipped\n");
		}
	}
	return 0;
} 

 L1-060 心理阴影面积

 

#include <stdio.h>
int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d",50*(x-y));
	return 0;
}

 蓝桥杯 幸运数

#include <stdio.h>
int a[5][10000]={0};
void judge(int x)
{
  int sum=0,i=0;
  while(x>0){
    sum+=x%10;
    i++;
    x/=10;
  }
  a[i][sum]++;//计算i位数和为sum的数有多少个
}
int main()
{
  int count=0;
  for(int i=1;i<=9999;i++)
    judge(i);//遍历1到9999去进行运算(拆分100000000)(左边的数)
  for(int i=1;i<=4;i++){
    for(int j=1;j<=9*i;j++){
      for(int k=1;k<=i;k++){
        count+=a[i][j]*a[k][j]; //左边的种数数乘以右边的种数,右边不够位数可补零(左边不可补零所以选右边)
      }
    }
  }
  printf("%d\n",count);
  return 0;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值