3 条题解

  • 2
    @ 2025-11-7 20:58:01
    #include <bits/stdc++.h>
    using namespace std;
    int main(){
        int n,m;
        cin>>n;
        int nums[100000];  
        for(int i=0;i<n;i++)
            cin>>nums[i];
        cin>>m;    
        int first=0;
        int sums=0;    
        for (int i=0;i<n;i++){
            if(nums[i]==m){
                sums++;
                if(first==0){
                    first=i+1;
                }
            }
        }    
        cout<<first<<" "<<sums<<endl;  
        return 0;
    }
    • 0
      @ 2026-8-12 14:58:05
      # include <bits/stdc++.h>
      
      using namespace std;
      map<int,pair<int,int> >q;
      int n,m,x;
      int main(){
      	cin>>n;
      	for(int i = 1;i<=n;i++){
      		cin>>x;
      		if(q[x].first==0)q[x].second=i;
      		q[x].first++;
      	}
      	cin>>m;
      	int k=q[m].second;
      	if(k==0){
      		cout<<0<<" "<<0;
      		return 0;
      	}
      	cout<<k<<' '<<q[m].first;
      	return 0;
      } 
      
      • 0
        @ 2023-3-29 20:16:36

        纯查找

        #include<iostream>
        using namespace std;
        int a[100001],n,m,cnt,wz;
        int main(){
        	cin>>n;
        	for(int i=1;i<=n;i++)cin>>a[i];
        	cin>>m;
        	for(int i=1;i<=n;i++){
        		if(a[i]==m){
        			if(wz==0)wz=i;
        			cnt++;
        		}
        	}
        	cout<<wz<<" "<<cnt;
        	return 0;
        }
        
        • 1

        信息

        ID
        1019
        时间
        1000ms
        内存
        128MiB
        难度
        6
        标签
        递交数
        217
        已通过
        66
        上传者