题目大意:输入一个数n,再输入一段长度为n只含01的字符串,然后输入n个数,如果该数对应字符串中为1,把这个数加到sum中,然后根据范围输出相应结果
思路:直接上码
代码如下:
#include<stdio.h>
int main()
{
char a[20000];
int s[20000],n,i,t,sum,year,cnt;
scanf("%d",&t);
while(t--)
{
scanf("%d %s",&n,a);
sum=year=cnt=0;
for(i=0;i<n;i++)
{
scanf("%d",&s[i]);
if(a[i]=='1')
sum+=s[i],cnt++;
}
if(sum==0) year=0;
else if(sum<20) year=3;
else if(sum<30) year=5;
else if(sum<40) year=10;
else if(sum<50) year=15;
else if(sum<60) year=20;
else if(sum<70) year=25;
else if(sum<80) year=30;
else if(sum<90) year=35;
else year=40;
printf("Samuel was accused with %d case(s),and he will stay in the prison for %d year(s).\n",cnt,year);
}
return 0;
}