您的位置:首页 > 其它

Rational Grading UVALive - 7636

2017-04-19 13:12 232 查看
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5658

Grading exam scripts of a programming course is often a pain and to reduce the pain teachers often

give full marks only when the examinee’s output matches exactly with the correct one. Then the mark

can be easily calculated as a percentage of matching. But in some scenario, this approach may not be

right — especially in those cases where the output of each step depends on that of the previous one.

For example in the figure below you can see a program and its correct output. The 2nd, 3rd and 4th

output depends on the output of the previous lines. So if the output of the first line is wrong and the

next three lines are correct the examinee should not get 3 marks because he has made mistakes in all

four cases (Or made a mistake while copying from his friend).

So to grade such a program we adopt the following new policy — we should judge the correctness

of each line based on the output of the immediate previous line. For example, if for the program above

if someone’s output is:

1000

1000

1001

999

He/she should get 3 marks. Because, the output of the first line is incorrect but based on that line’s

output, the output of next three lines are correct.

Given a program’s description and its output, you job is to calculate the mark that the examinee

will get.

Input

There are at most 1001 test cases. The description of each test case is given below:

Each test case starts with two integers ivalue (0 < ivalue10 ≤ 100000010) and t (0 < t ≤ 30). Here

ivalue denotes the initial value of the variable i. This value can be in decimal (leftmost digit is not

zero), octal (leftmost digit is zero) or hexadecimal (starts with ‘0x’ and non-numeric digits will be in

uppercase). t denotes the total number of printing statements in the program. Each of the next t lines

contains an expression that the printing function will print followed by the output for the expression

written by the examinee. The expressions can be anyone from the following instruction set, s = {i++,

++i, i–, –i, i}, the output value will be between 0 and 1000000 (inclusive) and of course in

decimal.

Input is terminated by a line containing two zeroes.

Output

For each test case produce one line of output. This line contains the mark that the student will get

according to the new policy.

Illustration of 2nd Sample Input

Sample Input

766 4

++i 767

i++ 767

i– – 768

– –i 766

0766 4

++i 789

i++ 789

i– – 790

– –i 788

0x766 4

++i 1895

i++ 1895

i– – 1896

– –i 1894

0 0

Sample Output

4

3

4

blablabla:

题目并不难。。。

WA了九次。。昨天心态确实炸了

静不下心去分析= =

十六进制会有字母,

这是个小坑。。在判断的时候

如果判断数据输错了 并不都是n=t

如果是i++ t,n就应该等于t+1

同理在i– t,t错了n就应该等于t-1

下面是修改后的AC代码

= =我应该写个函数计算输入的字符串

#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[2000];
int i,j;
int q;
int n;
while(scanf("%s %d",s,&q),q!=0)
{
n=0;
int l;
int len=strlen(s);
if(s[<
d053
span class="hljs-number">0]=='0'&&s[1]=='x')
{
l=1;
for(i=len-1; i>1; i--)
{
if(s[i]=='A')
{
n+=10*l;
}
else if(s[i]=='B')
{
n+=11*l;
}
else if(s[i]=='C')
{
n+=12*l;
}
else if(s[i]=='D')
{
n+=13*l;
}
else if(s[i]=='E')
{
n+=14*l;
}
else if(s[i]=='F')
{
n+=15*l;
}
else if(s[i]>='0'&&s[i]<='9')
{
n+=(s[i]-'0')*l;
}
l*=16;
}
}
else if(s[0]=='0'&&s[1]!='x')
{
l=1;
for(i=len-1; i>0; i--)
{
if(s[i]>='0'&&s[i]<='7')
{
n+=(s[i]-'0')*l;
l*=8;
}
}
}
else
{
l=1;
for(i=len-1; i>=0; i--)
{
if(s[i]>='0'&&s[i]<='9')
{n+=(s[i]-'0')*l;
l*=10;}
}
}
int score=0;
while(q--)
{
char st[4];
int t;
scanf("%s %d",st,&t);
if(strcmp("++i",st)==0&&++n==t)
{
score++;
}
else if(strcmp("i++",st)==0)
{
if(n++==t)
score++;
else n=t+1;
}
else if(strcmp("i--",st)==0)
{
if(n--==t)
score++;
else
n=t-1;
}
else if(strcmp("--i",st)==0&&--n==t)
{
score++;
}
else if(strcmp("i",st)==0&&n==t)
{
score++;
}
else
{
n=t;
}
}
printf("%d\n",score);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: