杭电oj2030-2039————C语言

2030.汉字统计
http://acm.hdu.edu.cn/showproblem.php?pid=2030


#include <stdio.h>
#include <string.h>

int main(void)
{
    int n;
    int count;
    char c;

    scanf("%d%*c", &n);

    while (n--)
    {
        count = 0;

        while ((c = getchar()) != '\n')
        {
            if (c < 0)
                count++;
        }

        printf("%d\n", count / 2);
    }

    return 0;
}

2031.进制转换
http://acm.hdu.edu.cn/showproblem.php?pid=2031
和2051.Bitset相似

#include<stdio.h>
#include<string.h>
int main(){
    int n,i,r,j,flag;
    int s[1000];
    while(scanf("%d %d",&n,&r)!=EOF){
        flag = 0;
        if(n<0){flag=-1;n=-n;}
        i = 0;
        for(i=0;n!=0;i++){
            s[i] = n%r;
            n = n/r;
        }

        if(flag==-1){printf("-");}
        
        for(j=i-1;j>=0;j--){
            if(s[j]==10){printf("A");}
            else if(s[j]==11){printf("B");}
            else if(s[j]==12){printf("C");}
            else if(s[j]==13){printf("D");}
            else if(s[j]==14){printf("E");}
            else if(s[j]==15){printf("F");}
            else{printf("%d",s[j]);}
        }
        printf("\n");
    }
}

2032.杨辉三角
http://acm.hdu.edu.cn/showproblem.php?pid=2032

#include<stdio.h>
int main() 
{
	int n;
	int a[30][30] = { 0 };
	while (scanf("%d", &n) != EOF) {
		printf("1\n");//输出第一行

		for (int i = 1; i < n; i++) {   //控制要输入的多少行
			a[i][0] = 1;          //把所有行的第一个和最后一个变为1
			a[i][i] = 1;
		printf("1 ");   //输出每一行的第一个数1

			for (int j = 1; j < i ; j++) {     //从第三行才开始使用这个规律,
			a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
			printf("%d ", a[i][j]);
			}
		printf("1\n");//输出每一行的最后一个数1
		}
		printf("\n");
	}
	return 0;
}

2033.人见人爱A+B
http://acm.hdu.edu.cn/showproblem.php?pid=2033

#include <stdio.h>
int main()
{
	int h1,m1,s1,h2,m2,s2,n;
	scanf("%d",&n);
	while(n--){
		scanf("%d%d%d%d%d%d",&h1,&m1,&s1,&h2,&m2,&s2);
		int x=0,y=0,z=0;
		x=s1+s2;y=m1+m2;
		if(x>=60) {y+=1;x=x%60;}//进位加1,不可能进2,进位后求余数就行
		z=h1+h2;
		if(y>=60) {z+=1;y=y%60;}
		printf("%d %d %d\n",z,y,x);
	}
	return 0;
}

2034.人见人爱A-B
http://acm.hdu.edu.cn/showproblem.php?pid=2034

#include<stdio.h>
int main(){
    int n,m,i,j,num,flag,temp,s[101],o[101],p[101];
    while(~scanf("%d %d",&n,&m)){
        if(n==0&&m==0){break;}
        for(i=0;i<n;i++){scanf("%d",&s[i]);}
        for(i=0;i<m;i++){scanf("%d",&o[i]);}
        num = 0;
        for(i=0;i<n;i++){
            flag = 0;
            for(j=0;j<m;j++){
                if(s[i]==o[j]){flag=1;}//记的是i的不是j的
            }
            if(flag==0){p[num]=s[i];num++;}
        }
        if(num==0){printf("NULL");}//不要有回车否则会多一行
        
        for(i=0;i<num;i++){//选择排序(否则从小到大输出结果)题目给了要求
            for(j=i+1;j<num+1;j++){
                if(p[i]>p[j]){
                    temp = p[i];
                    p[i] = p[j];
                    p[j] = temp;
                }
            }
        }
        for(i=0;i<num;i++){
            printf("%d ",p[i]);//每个后必有空格,题目要求
        }
        printf("\n");

    }
}

2035.人见人爱A^B
http://acm.hdu.edu.cn/showproblem.php?pid=2035

#include <stdio.h>
int main()
{
	int a,b;
	while(~scanf("%d%d",&a,&b)){
		if(a==0&&b==0)break;
		int sum=1;
		for(int i=0;i<b;i++){
			sum=sum*a%1000;//不要先把数求出来再求余数,有可能会超过long long的范围,也很慢
		}
		printf("%d\n",sum);
	}
	return 0;
}

2036.改革春风吹满地
http://acm.hdu.edu.cn/showproblem.php?pid=2036
面积公式
在这里插入图片描述

#include <stdio.h>
int main()
{
    int n;
    int x[105],y[105];
    double sum;
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        sum=0;
        scanf("%d%d",&x[1],&y[1]);//第一个点
        for(int i=2; i<=n; i++)
        {
            scanf("%d%d",&x[i],&y[i]);            
            sum+=abs(x[i-1]*y[i]-x[i]*y[i-1]);
        }
        sum+=abs(x[n]*y[1]-y[n]*x[1]);//首尾相连
        printf("%.1lf\n",sum/2);
    }
    return 0;
}


2037.今年暑假不AC

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

#include <stdio.h>
int a[100],b[100];
int main()
{
    int n,i,j;
    while(~scanf("%d",&n)&&n!=0){
        for(i=0;i<n;i++)
           scanf("%d %d",&a[i],&b[i]);//a[]开始时间,b[]结束时间
        int count=1;int t;
        for(i=0;i<n-1;i++)//选择排序、按照结束时间排序
            for(j=i+1;j<n;j++)
            	if(b[i]>b[j]){
                	t=b[i];b[i]=b[j];b[j]=t;
                	t=a[i];a[i]=a[j];a[j]=t;
            	}
            	
        int y=b[0];//第一个结束时间
 		for( int i=1;i<n;i++){
            if(y <= a[i]){//找到比前一个结束时间还晚的开始时间
               y=b[i];//y只是个无情的结束时间,与i无关
               count++;
            }
        }
        printf("%d\n",count);
    }
    return 0;
}

2039.三角形
http://acm.hdu.edu.cn/showproblem.php?pid=2039

#include <stdio.h>
int main()
{
	float a,b,c;int m;
	scanf("%d",&m);
	while(m--){
		while(~scanf("%f%f%f",&a,&b,&c)){
			if(a+b>c&&a+c>b&&b+c>a)//两边之和大于第三边
				{printf("YES");}
			else
				{printf("NO");}
			printf("\n");
		}
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值