热身赛的水题
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<T<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<n<=100), the second line is a series of 0 and 1. 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
中南大学第五届大学生程序设计竞赛-热身赛
刚开始没顺利AC主要是experience 的sum函数写错了,连续两天得到的experience应该是10+20为30;sum+=30;依此类推。
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int sum_all;
void output()
{
if(sum_all>=0&&sum_all<50) cout<<0<<endl;
else if(sum_all>=50&&sum_all<150) cout<<1<<endl;
else if(sum_all>=150&&sum_all<250) cout<<2<<endl;
else if(sum_all>=250&&sum_all<350) cout<<3<<endl;
else if(sum_all>=350&&sum_all<450) cout<<4<<endl;
else if(sum_all>=450&&sum_all<550) cout<<5<<endl;
else if(sum_all>=550&&sum_all<650) cout<<6<<endl;
else if(sum_all>=650&&sum_all<750) cout<<7<<endl;
else cout<<8<<endl;
}
int main()
{
int T;
cin>>T;
int n;
string str1;
int sum=0;
int count=0;
for(int i=0;i<T;i++)
{
cin>>n;
cin>>str1;
sum_all=0;
for(int j=0;j<str1.length();)
{
while(str1[j++]=='1')
{
count++;
}
sum+=(count/5)*(10+20+30+40+50);//初始经验值
switch(count%5)
{
case 1: sum+=10;
break;
case 2: sum+=30;
break;
case 3: sum+=60;
break;
case 4: sum+=100;
break;
default :
break;
}
count=0;
sum_all+=sum;
sum=0;
}
output();
}
return 0;
}
/**********************************************************************
Problem: 1003
User: 0902170512
Language: C++
Result: AC
Time:8 ms
Memory:2024 kb
**********************************************************************/