罗迎甲 • 5个月前
Online Judge
×提交成功
19按规则查找数组中的数据
已知一个数组有n个数字,这n个数字的最大值为n,请查找数组的第一个数字a1,再查找数组的第a1个数字,如此共查找m个数字。
第一行为数字n,m,分别代表数组的大小与查找次数(n<1000)。 接下来一行输入n个数字ai(1<=ai<=n);
共输出m个数字,每个数字后一个空格,行末换行。
input
5 2 5 2 3 1 4
output
5 4
lema
Time limit | 1 second |
Memory limit | 128 MB |
提交记录
刚刚 | Accepted | |
刚刚 | Accepted | |
11分钟前 | Accepted | |
54分钟前 | Wrong Answer |
×
Run ID:102425
提交时间:2024-12-21 16:07:44
#include<iostream> // cin\cout\endl #include<cstdio> //scanf()\printf() #include<cstring> // strcpy()\strcat()\strcmp()\strlen()\memset() #include<cmath> //sqrt()\pow()\abs()\ceil()\floor()\max()\min() using namespace std; int main(){ int x=0,c=0,b=0,n=0; cin>>n; int a[10086]={}; for(int z=1;z<=3*n;z++) { cin>>x; a[x]++; } for(int z=1;z<=n;z++) { if(a[z]>b) { b=a[z]; c=z; } } cout<<c; return 0; }
© C++题库系统 OJ 2024
评论: