码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 1038

时间:2020-07-24 21:47:22      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:image   输出   ace   stream   for   ret   通过   names   scanf   

技术图片

#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
int input,search;
scanf("%d",&input);

int *score = new int[input];

for(int i=0;i<input;++i)
{
    scanf("%d",&score[i]);
}

scanf("%d",&search);
int *search_score = new int[search];

for(int j=0;j<search;++j)
{
    scanf("%d",&search_score[j]);
}

int num[100] = {0};

int flag=0;
for(int x=0;x<input;++x)
{
flag = score[x];
num[flag]++;
}

//以下为正确做法,不会出现错误
for(int y=0;y<search;++y)
{
flag = search_score[y];
cout<<num[flag];
if(y!=search-1) cout<<" ";
}
return 0;
}

之前做此题时用了不严谨的输出方法,所以第四个监测点一直通过不了,以后慎用。

代码如下:
int temp = search_score[0];
cout<<num[temp];

for(int y=1;y<search;++y)
{
flag = search_score[y];
cout<<" "<<num[flag];
}

PAT 1038

标签:image   输出   ace   stream   for   ret   通过   names   scanf   

原文地址:https://www.cnblogs.com/kayden-su/p/13374154.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!