现在的位置: 首页 > 综合 > 正文

hdu1166 敌兵布阵

2013年05月06日 ⁄ 综合 ⁄ 共 439字 ⁄ 字号 评论关闭

 

#include<stdio.h>
#include<string.h>
#define max 50001
int x[max];
int main()
{
	int t,i,n,a,b,j,sum,m;
	char str[10];
	scanf("%d",&m);
	for(t=1;t<=m;t++){
		printf("Case %d:\n",t);
		scanf("%d",&n);
		for(i=1;i<=n;i++)
			scanf("%d",&x[i]);
		while(1)
		{
			scanf("%s",str);
			if(strcmp(str,"End")==0)
				break;

			scanf("%d %d",&a,&b);

			if(strcmp(str,"Add")==0)
				x[a]+=b;
			if(strcmp(str,"Sub")==0)
				x[a]-=b;
			if(strcmp(str,"Query")==0){
				sum=0;
				for(j=a;j<=b;j++)
					sum+=x[j];
				printf("%d\n",sum);
			}
		}

	}
	return 0;
}

抱歉!评论已关闭.