Description
Brother Xi has recently bought a smart mobile phone. Now he surfs Internet by his mobile phone almost every day. The browser that he uses is UC Browser, which is one of the most popular mobile browsers. To better grasp the users, UC Corporation have also brought out the level system of user account. The higher the level of your account, the more privileges you can enjoy. The level of your account is calculated by your experiences. The correspondence of level and experience is as follows:
Level | Experiences | Level | Experiences | Level | Experiences |
---|---|---|---|---|---|
0 | 0-49 | 3 | 250-349 | 6 | 550-649 |
1 | 50-149 | 4 | 350-449 | 7 | 650-749 |
2 | 150-249 | 5 | 450-549 | 8 | :>=750 |
You can get 10 experiences after using UC Browser one day in a row, 20 experiences for two days in a row, 30 experiences for three days in a row, 40 experiences for four days in a row, 50 experiences for five days in a row. If you use UC Browser six days in a row, the experiences you can get will be equal 10, like your using UC Browser one day in a row. It’s come back to the starting of your using UC Browser. It’s a circle.
Now you have known the Xi’s record of using UC Browser, I’ll hope you calculate the level of Xi’s account.
Input
The first line of the input contains a single integer T (0 ~120) which is the number of test cases, followed by 2*T lines. For each test case, the first line is the number of days n (0~100), the second line is a series of 0 and 1. Where 0 stands for not using UC browser on that day and 1 stands for using UC browser on that day.
Output
For each test case, output the corresponding level of Xi’s account in one line.
Sample Input
2 6 110101 12 111111110101
Sample Output
1 2
Hint
Source
中南大学第五届大学生程序设计竞赛-热身赛
题目链接:COJ 1003
题意:给你一段连续字符,‘1’代表用了UC,‘0’代表没用UC,遇到1时加10倍于连续用的天数的经验,5天一个周期,遇到0时重新开始,最后判断总经验值在哪个范围即可输出用户等级。
AC代码
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
string s;
cin>>n>>s;
int sum=0, flag=1;
for(int i=0; i<n; i++)
{
if(s[i]=='0') flag=1;
else
{
if(flag==6) flag=1;
sum+=(flag*10);
++flag;
}
}
if(sum < 50) cout<<"0\n";
else if(sum < 150) cout<<"1\n";
else if(sum < 250) cout<<"2\n";
else if(sum < 350) cout<<"3\n";
else if(sum < 450) cout<<"4\n";
else if(sum < 550) cout<<"5\n";
else if(sum < 650) cout<<"6\n";
else if(sum < 750) cout<<"7\n";
else cout<<"8\n";
}
return 0;
}