问题:http ://www.spoj.com/problems/EGYPIZZA/
很长一段时间以来,我一直在尝试解决这个“PIZZA”问题,我尝试了很多很多输入,它似乎在我的机器上运行良好,但在线法官一直拒绝接受 mu 代码,说它的答案是错误的! !请帮帮我......这是我的代码:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char str[4],b[3][4]= {"1/4","1/2","3/4"};
unsigned int n, s = 1, count1 = 0, count2 = 0, count3 = 0;
scanf("%u",&n);
while(n--)
{
cin>>str;
if(strcmp(str,b[0])==0)
count2++;
else if(strcmp(str,b[1])==0)
count1++;
else if(strcmp(str,b[2])==0)
count3++;
}
while(count3!=0 && count2!=0)
{
count2--; count3--; s++;
}
if(count1%2!=0)
if(count2/2!=0)
{
count2-=2; count1--; s++;
}
s = s + (count1/2) + (count1%2) + (count2/4) + (count2%4) + count3 ;
printf("%u\n",s);
return 0;
}
编辑:
根据您的建议,我已经更新了我的代码,请大家看看!!还是给错答案。。