XDOJ部分例题及答案第三更 出租车计价 出租车计价2 除法计算器 大小 单词统计

目录

出租车计价

出租车计价2

除法计算器

大小

单词统计


出租车计价

#include<stdio.h>
int main()
{
	float s;
	int t,y;
	scanf("%f%d",&s,&t);
	if(s<=3){
		y=10;
	}else{
		if(s<=10){
			y=10+(s-3)*2;
		}else{
			y=10+7*2+(s-10)*3;
		} 
	}
	printf("%d",t/5*2+y);

}

出租车计价2

#include<stdio.h>
int main()
{
    int m, b, c;
    double a, n, sum;
    
    scanf("%lf%d",&n,&m);
    if(n<=3)
        a=10;
    else if(n<=10)
        a=10+2*(n-3);
    else
        a=24+(n-10)*3;
    b=m/5*2;
    sum=a+b;
    c=(int)((sum*1)+0.5)/1.0;
    printf("%d",c);
    
    return 0;
}

除法计算器

#include<stdio.h>
int main()
{
	int m,n,q,r,a,b;
	scanf("%d%d%d%d",&m,&n,&q,&r);
	a=m/n;
	b=m%n;
	if(q==a&&r==b){
		printf("yes");
	}else{
		printf("%d %d",a,b);
	}
		
}

大小

#include<stdio.h>
int max(int a,int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
int min(int a,int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
int main()
{
	int a,m,n,i;
	scanf("%d",&n);
	m=a=n%10;
	while(n>0){
		i=n%10;
		n=n/10;
		m=max(m,i);
		a=min(a,i);
	}
	printf("%d %d",m,a);
	
 } 

单词统计

#include<stdio.h>
#include<string.h>
int main(){
	char s[100],w[8];
	int i,count=0,count1=0;
	gets(s);
	gets(w);
	for(i=0;i<strlen(s);i++){
		if(s[i]==w[count]){
				count++;
			}
		if(count==strlen(w)){
			if((s[i+1]==' '||i+1==strlen(s))&&((s[i-strlen(w)]==' ')||i-strlen(w)==-1)){
				count1++;
			}
			count =0;
		}
		if(s[i]==' '){
			count =0;
		}
	}
	printf("%s %d",w,count1);
} 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值