L1-043 阅览室
我算是知道了emm,天梯赛的题都是傻逼题,但是就是各种细节坑,cnm
不注意细节你吃枣要完蛋
AC版
#include <iostream>
#include <map>
using namespace std;
map<int,pair<int,int> > mm;
bool book[1005];
int main()
{
int n;
scanf("%d",&n);
getchar();
for(int i=0;i<n;i++)
{
mm.clear();
int x,h,m,t;
char c,mc;
int cnt=0,sum=0;
for(int i=0;i<1005;i++)
book[i]=false;
cin>>x>>c>>h>>mc>>m;
while(x)
{
if(c=='S')
{
t=h*60+m;
mm[x].first=t;
book[x]=true;
}else if(book[x]&&c=='E')//单纯想以first存不存在作为标记是不够的,有可能出现 S E E的情况
{
t=h*60+m;
mm[x].second=t;
cnt++;
sum+=mm[x].second-mm[x].first;
book[x]=false;//解决S E E的情况
}
cin>>x>>c>>h>>mc>>m;
}
//cout<<"!! "<<sum<<endl;
if(cnt)
{
if(sum%cnt==0)
printf("%d %d\n",cnt,sum/cnt);
else
{
double t=sum*1.0/cnt+0.5;
int dt=t;
printf("%d %d\n",cnt,dt);
}
//printf("%d %d\n",cnt,sum/cnt+0.5);//+1处理错误,应该四舍五入
}
else
printf("0 0\n");
}
return 0;
}
未AC版 12分
我感觉这个版本已经挺完美的了,关于需要注意的以下坑点都解决了
1.四舍五入
2. S S E 情况
3. S E E 情况
4. S E S E情况
5. 分母 cnt 为 0
我就纳闷了,到底还有啥 是聪明的我没想到的???
好的,其实是很完美的,就是字符串处理出错了emmm,全部给他换成数据分别输入就AC了,emmmm
更神奇的是,用cout<<s[4]<<" "<<s[5]<<" "<<s[7]<<" "<<s[8]<<endl;
调试,输出的完全没毛病,简直玄学了emmm
#include <iostream>
#include <map>
using namespace std;
map<char,pair<int,int> > mm;
bool book[1005];
int main()
{
int n;
scanf("%d",&n);
getchar();
for(int i=0;i<n;i++)
{
mm.clear();
string s;
getline(cin,s);
int t;
int cnt=0,sum=0;
for(int i=0;i<1005;i++)
book[i]=false;
while(s[0]!='0')
{
if(s[2]=='S')
{
t=(s[4]-'0')*10+(s[5]-'0');
t=t*60;
t+=(s[7]-'0')*10+(s[8]-'0');
mm[s[0]-'0'].first=t;
book[s[0]-'0']=true;
}else if(book[s[0]-'0']&&s[2]=='E')//单纯想以first存不存在作为标记是不够的,有可能出现 S E E的情况
{
t=(s[4]-'0')*10+(s[5]-'0');
t=t*60;
t+=(s[7]-'0')*10+(s[8]-'0');
mm[s[0]-'0'].second=t;
cnt++;
sum+=mm[s[0]-'0'].second-mm[s[0]-'0'].first;
book[s[0]-'0']=false;//解决S E E的情况
}
getline(cin,s);
}
//cout<<"!! "<<sum<<endl;
if(cnt)
{
if(sum%cnt==0)
printf("%d %d\n",cnt,sum/cnt);
else
{
double t=sum*1.0/cnt+0.5;
int dt=t;
printf("%d %d\n",cnt,dt);
}
//printf("%d %d\n",cnt,sum/cnt+0.5);//+1处理错误,应该四舍五入
}
else
printf("0 0\n");
}
return 0;
}