OpenJudge1.6答案

01:与指定数字相同的数的个数


#include <stdio.h>
#include <math.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[])
{
	int n,medium,m[100],i=1,count=0;
	scanf("%d",&n);
	while(i<=n)
	{
		scanf("%d",&m[i]);
		i++;
	}
	i=1;
	scanf("%d",&medium);
	while(i<=n)
	{
		if(m[i]==medium)
		{
			count++;
		}
		i++;
	}
	printf("%d",count);
}

02:陶陶摘苹果

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {

	int a,h[11],i=1,count=0,high;
	while(i<=10)
	{
		scanf("%d",&h[i]);
		++i;
	}
	scanf("%d",&high);
	for(i=1;i<=10;++i)
	{
		if(high+30>=h[i])
		{
			++count;
		}
	}
	printf("%d",count);
	return 0;
}

03:计算书费

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(int argc, char *argv[])
{
	int num[11],i=1;
	float sum=0;
	while(i<=10)
	{
		scanf("%d",&num[i]);
		i++;
	}
	i=1;
	switch(i)
	{
		case 1:sum+=num[i]*28.9;
				i++;
		case 2:sum+=num[i]*32.7;
				i++;
		case 3:sum+=num[i]*45.6;
				i++;
		case 4:sum+=num[i]*78.0;
				i++;
		case 5:sum+=num[i]*35.0;
				i++;
		case 6:sum+=num[i]*86.2;
				i++;
		case 7:sum+=num[i]*27.8;
				i++;
		case 8:sum+=num[i]*43.0;
				i++;
		case 9:sum+=num[i]*56.0;
				i++;
		case 10:sum+=num[i]*65.0;
				i++;
				break;
	}
	printf("%.1f",sum);
}

04:数组逆序重放

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	int a[100],n,i=1;
	scanf("%d",&n);
	while(i<=n)
	{
		scanf("%d",&a[i]);
		++i;
	}
	for(i=n;i>=1;--i)
	{
		cout<<a[i]<<" ";	
	}		
	return 0;
}

05:年龄与疾病

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <iomanip>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	int n,age[101],i=1,count[5],sum;
	float average;
	count[1]=count[2]=count[3]=count[4]=0;
	scanf("%d",&n);
	while(i<=n)
	{
		scanf("%d",&age[i]);
		if(age[i]>=-1&&age[i]<=18)
		{
			count[1]++;
		}
		else if(age[i]>=19&&age[i]<=35)
		{
			count[2]++;	
		}		
		else if(age[i]>=36&&age[i]<=60)
		{
			count[3]++;
		}
		else
		{
			count[4]++;
		}
		i++;
	}
	sum=(count[1]+count[2]+count[3]+count[4]);
	for(i=1;i<=4;i++){
	average=count[i]*1.0/n*100;
	printf("%.2f%%\n",average);
}
	return 0;
}

06:校门外的树

#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	int a[10001]={0},i=1,l,m,count=0,start,end,j;

   cin>>l>>m;
    for(int i=0;i<m;i++){
        cin>>start>>end;
        for(int j=start;j<=end;j++)
            a[j]=1;   
    }
 for(int i=0;i<=l;i++)
        if(a[i]==0)
            count++;
	cout<<count;
	return 0;
}

  • 0
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值