杭电oj2010-2019————C语言

2010水仙花数
http://acm.hdu.edu.cn/showproblem.php?pid=2010

#include <stdio.h>
int main(){
    int m,n,i,a,b,c,flag=0;
    while(scanf("%d %d",&m,&n)!=EOF){
        for(i=m;i<=n;i++){
            a=i%10;//个位
            b=i/10%10;//十位
            c=i/100;//百位
            if(a*a*a+b*b*b+c*c*c==i){
                if(flag==1)printf(" ");//为了输出空格
                printf("%d",i);//以防最后一位多个空格会格式错误
                flag=1;
            } 
        }
        if(flag==0) printf("no\n");
        else printf("\n");
        flag=0;
    }
    return 0;
}

2011多项式求和
http://acm.hdu.edu.cn/showproblem.php?pid=2011

#include <stdio.h>
#include <math.h>
int main()
{
	float i,j,sum;int n;
	scanf("%f",&j);
	while(j--){
		while(~scanf("%d",&n)){
			sum=0;
			for(i=1;i<=n;i++){
    			sum+=pow(-1,i+1)*(1.0/i);//为了偶数前的负号需要负一的次方
			}
			printf("%.2f\n",sum);
		}
	}
	return 0;
}

2012素数判定
http://acm.hdu.edu.cn/showproblem.php?pid=2012

#include <stdio.h>
int main()
{
	int x,y,n,s;
	while(~scanf("%d%d",&x,&y)){
		if(x==0&&y==0) break;
			int flag=1;
		for(n=x;n<=y&&flag==1;n++){
			s=n*n+n+41;
			for(int j=2;j<s&&flag==1;j++){
   				if(s%j==0) {flag=0;printf("Sorry\n");}
			}
		}
		if(flag==1) printf("OK\n");
	}
	return 0;
}

2013蟠桃记
http://acm.hdu.edu.cn/showproblem.php?pid=2013

#include <stdio.h>
int main()
{
	int n,sum=1,day1,day2;//day1前一天的,day2今天的
	while(~scanf("%d",&n)){
    	day2=1;
		for(int i=n;i>1;i--){
			day1=(day2+1)*2;
			day2=day1;
		}
		printf("%d\n",day1);
	}
	return 0;
}

2014青年歌手大奖赛_评委会打分

http://acm.hdu.edu.cn/showproblem.php?pid=2014

#include <stdio.h>
int main()
{
	float sum=0;int j,i=0;float a[100];
	while(~scanf("%d",&j)){
		for(i=0;i<j;i++) {scanf("%f",&a[i]);}
		float max=a[0];float min=a[0];
		for(int m=0;m<j;m++){
			if(a[m]>max) max=a[m];//这种不需要下标
			if(a[m]<min) min=a[m];
			sum+=a[m];
		}
		printf("%.2f\n",(sum-max-min)/(j-2));
		sum=0;
	}
	return 0;
}

2015偶数求和
http://acm.hdu.edu.cn/showproblem.php?pid=2015

#include<stdio.h>
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m)){
		int i=0,sum=0,a[100];
		a[0]=2;
 		int b=n/m,d=n%m;//b是不包括最后一组的组数,d是最后一组的个数
    	for(int c=1;c<=b;c++){//计算前b个组的每一组
     		for (i=0;i<m;i++){//每组只有m个
            	sum+=a[i];
            	a[i+1]=a[i]+2;
        	}
        	printf("%d",sum/m);
        	a[0]=a[i];
        	sum=0;
        	if (c<b)
            	printf(" ");
   	 	}
    	if(n%m!=0){//如果最后不足m个,则以实际数量求平均值 
        	int sum2=0;
    		for (i=0;i<(n%m);i++){
        		sum2+=a[i];
        		a[i+1]=a[i]+2;
        	}
       		printf(" %d",sum2/(n%m));
    	}
		printf("\n");
	}
	return 0; 
}

2016数据的交换输出
http://acm.hdu.edu.cn/showproblem.php?pid=2016

#include <stdio.h>
int main()
{
    int n,i,min;
    int t,a[100];
    while(~scanf("%d",&n)){
        if(n==0)
            break;
        min=0;
        for(i=0; i<n; i++){
            scanf("%d",&a[i]);
            if(a[min]>a[i])  min=i;//这种可以找到下标
        }
        //交换
        if(min) {t=a[0];a[0]=a[min];a[min]=t;}
        
        for(i=0; i<n-1; i++)  //输出注意最后一个后不要空格
            printf("%d ",a[i]);
        printf("%d\n",a[n-1]);
    }
    return 0;
}

2017字符串统计

http://acm.hdu.edu.cn/showproblem.php?pid=2017

#include <ctype.h>
#include <stdio.h>
int main(void)
{
    int n, d;
    char c;
    scanf("%d%*c", &n);//避免回车也算进字符
    while (n--){
        for (d = 0 ; (c = getchar()) != '\n' ;){
            if (isdigit(c)) d++;
        }
        printf("%d\n", d);
    }
    return 0;
}

2018母牛的故事

http://acm.hdu.edu.cn/showproblem.php?pid=2018

#include <ctype.h>
#include <stdio.h>

int main(void)
{
    int n,i;
    int fab[55] = {1,2,3,4,6};
    for (i=5;i<55;i++)
        fab[i]=fab[i-1]+fab[i-3];
        
    while(scanf("%d",&n),n){
        printf("%d\n", fab[n-1]);
    }
    return 0;
}

2019数列有序!

http://acm.hdu.edu.cn/showproblem.php?pid=2019

#include <stdio.h>

int main()
{
	int arr[105], n, x;
	while(~scanf("%d%d", &n,&x)){
		if(n==0&&x==0) break;
		for(int i = 0; i < n; i++){
			scanf("%d",&arr[i]);
		}
		int flags = 0;
		for(int i = 0; i < n; i++){
			if(arr[i] >= x && flags == 0){
				printf("%d %d", x, arr[i]);
				flags = 1;//找到第一个比插入的数大的,然后输出在前面一个位置
			}
			else
				printf("%d",arr[i]);//其他正常输出
			if(i != n - 1)
				printf(" ");//为了最后一个数后没有空格
		}
		if(flags == 0)
			printf("%d", x);//如果插入的数是最大的,前面数都正常输出了,然后再输出插入的数
			
		printf("\n");
	}
	return 0;
}
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值