Waiting for Change

题目大致意思:

学生向老师买书,每本书大致为15元,学生只有5元、10元和20元。老师没有零钱,所以一但出现20元的老师把他放到B中,等有零钱既15元的才能把书买给学生!!!题目大致是这样的

注意点:本题求的是B中最多存放多少的学生数(之前因为这个错了几次,本人比较水希望大神勿喷!)


<span style="font-family:KaiTi_GB2312;font-size:12px;">#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct st{
	char a[100];
};
int main()
{
	int t,n,sorce,i,b[101],g,start,toall,str;
	int max; 
	st s[101];
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		getchar();
		memset(b,'\0',101);
		for(str=max=toall=start=g=i=0;i<n;i++)
		{
			scanf("%s%d",s[i].a,&sorce);
			if(sorce<=15)toall-=1;
			else{
				toall+=1;
				b[g++]=i;
			}
			if(toall>0)
			{
				if(toall==1)
	 				start=g-1;//每当为1,即开始累加  
				else{
					if(sorce==15)start+=1; //每当有15遍向下移以为 
				}
				if(toall>max)
					max=toall,str=start;//统计最大的个数和下标 
			}
		}
		if(max<=0) 
			printf("Line B stayed empty.\n");
		else{
			for(i=0;i<max;i++)
				printf(i<(max-1)?"%s ":"%s\n",s[b[str+i]].a);
		}
	}
} </span>




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值