//1072 开学寄语v1
#include <iostream>
#include <map>
using namespace std;
int main(){
int N,M,i,j,t,tem,stucnt=0,goods=0,n; cin>>N>>M;
int check[M];
string name;
map<string,int> mp;
for(i=0;i<M;i++) cin>>check[i];
for(i=0;i<N;i++){ //N个学生
int k=1;
cin>>name>>n;
for(j=0;j<n;j++){
cin>> tem;
for(t=0;t<M;t++){
if(tem==check[t]){
goods++; //存在一件,要被计数
if(k==1){ //只输出一遍姓名
k--;
cout<<name<<":";
}
if(k==0) cout<<" "<<tem; //每次输出物品编号前有个空格
if(mp[name]==0){
mp[name]++;
stucnt++;
}
}
}
if(j==n-1) cout<<endl;
}
}
cout<<stucnt<<" "<<goods<<endl;
return 0;
}
1072 开学寄语,AC时三个测试都通不过,提示格式错误,答案错误,求助
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- Italink 2018-11-14 14:34关注
2个错误
1:由于物品为4位的数字,而你用int接受之后,会舍弃前面的0,要么你改用string,要么用iomanip里的函数或者printf控制输出
2,换行的问题,如果某个学生没有违禁物品,就不用输出他的信息(k仍为1);#include <iostream> #include<string> #include<iomanip> #include <map> using namespace std; int main() { int N, M, i, j, t, tem, stucnt = 0, goods = 0, n; cin >> N >> M; int check[8]; string name; map<string, int> mp; for (i = 0; i < M; i++) cin >> check[i]; for (i = 0; i < N; i++) { //N个学生 int k = 1; cin >> name >> n; for (j = 0; j < n; j++) { cin >> tem; for (t = 0; t < M; t++) { if (tem == check[t]) { goods++; if (k == 1) { k--; cout << name << ":"; } if (k == 0) cout << " " << setw(4) << setfill('0') << tem; //ERROR 1 if (mp[name] == 0) { mp[name]++; stucnt++; } } } if (j == n - 1 && k == 0) //ERROR 2 cout << endl; } } cout << stucnt << " " << goods << endl; return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog