实在不会求教

F. 今天你AC了吗

Problem ID: 9224

Contest ID: 5315

必做题

Wrong Answer

时间限制: 1s 空间限制: 256M

题目描述:

XJOI 计算每个用户的 AC 率的方法是将所有提交结果为AC的的数量除以提交的总数。

现给定某用户的提交记录:‘AAAAWAAACRTWWA’

字母“A”表示Accepted。 字母“W”表示Wrong Answer。 字母“C”表示Compile Error。 字母“T”表示超过Time Limit Exceeded。 字母“R”表示Runtime Error。

现在根据某位用户的提交记录,计算他的AC率('AC’表示当提交结果为’A’时)、WA率('WA’表示当提交结果为’W’时)和CE率(‘CE’表示当提交结果是’C’)。

输入格式:

输入包含字符的单行,字符串以’?'结尾 (这个输入字符只包括上面提到的大写字母和问号)

输出格式:

输出三行,分别代表用户的AC率、WA率和CE率(保留两位小数)。

样例输入:

AAAAWAAACRTTWWA?

样例输出:

0.53

0.20

0.07

约定:

字符的个数不超过 50

3 个赞

请发代码你们怎么都不发

3 个赞

思路:
①统计字符串总个数
②统计A W C的字符个数
③概率=出现次数/总长度(记得保留2位小数!printf(“%.2lf”,(概率))

1 个赞

怎么统计字符串及AWC的个数?

1 个赞

遍历一下啊

2 个赞

如果(我习惯)用string,长度:变量名.size()

1 个赞

先统计A、W、C的数量在用1分别除以它(保留两位输出)

1 个赞

思路如上,代码如下:
#include<bits/stdc++.h>
using namespace std;
int main()
{
char ch;
int a=0,c=0,w=0,tot=0;
while(cin>>ch,ch!=‘?’)
{
if(ch==‘A’)
{
a++;
}
if(ch==‘C’)
{
c++;
}
if(ch==‘W’)
{
w++;
}
tot++;
}
cout<<fixed<<setprecision(2)<<double(a)/tot<<endl;
cout<<fixed<<setprecision(2)<<double(w)/tot<<endl;
cout<<fixed<<setprecision(2)<<double(c)/tot<<endl;
return 0;
}

2 个赞

最好不要直接打代码

2 个赞
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char ch;
	int a=0,c=0,w=0,tot=0;
	while(cin>>ch,ch!=‘?’)
	{
		if(ch==‘A’)a++;
		if(ch==‘C’)c++;
		if(ch==‘W’)w++;
		tot++;
	}
	cout<<fixed<<setprecision(2)<<double(a)/tot<<endl;
	cout<<fixed<<setprecision(2)<<double(w)/tot<<endl;
	cout<<fixed<<setprecision(2)<<double(c)/tot<<endl;
	return 0;
}

帮你格式化

2 个赞