2 solutions

  • -2
    @ 2024-7-22 10:17:42

    数组:c++

    #include<bits/stdc++.h>
    using namespace std;
    const int N=100010;
    int q[N];
    int hh=0,tt=-1;
    int main()
    {
    	int n;
    	cin>>n;
    	while(n--)
    	{
    		string s;
    		cin>>s;
    		if(s=="push")
    		{
    			int t;
    			cin>>t;
    			q[++tt]=t;
    		}
    		else if(s=="pop")
    		{
    			hh++;
    		}
    		else if(s=="empty")
    		{
    			if(hh<=tt)
    			{
    				cout<<"NO"<<endl;
    			}
    			else
    			{
    				cout<<"YES"<<endl;
    			}
    		}
    		else
    		{
    			cout<<q[hh]<<endl;
    		}
    	}
    	return 0;
    }
    
    • -3
      @ 2024-7-22 10:18:36

      第二种:c++

      #include<bits/stdc++.h>
      using namespace std;
      queue<int> q;
      int main()
      {
      	int n;
      	cin>>n;
      	for(int i=1;i<=n;i++)
      	{
      		string a;
      		cin>>a;
      		if(a=="push")
      		{
      			int x;
      			cin>>x;
      			q.push(x);
      		}
      		if(a=="pop") q.pop();
      		if(a=="empty")
      		{
      			if(q.empty()) cout<<"YES"<<endl;
      			else cout<<"NO"<<endl;
      		}
      		if(a=="query")
      		{
      			cout<<q.front()<<endl;
      		}
      	}
      	return 0;
      }
      
      
      • 1

      Information

      ID
      162
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      1
      Tags
      (None)
      # Submissions
      81
      Accepted
      23
      Uploaded By