首页 > 其他分享 >2022/12 做题记录 #3

2022/12 做题记录 #3

时间:2022-12-20 21:34:00浏览次数:58  
标签:www 12 freopen 记录 int cin else 2022 模板

2022/12/20

B3614 【模板】栈

https://www.luogu.com.cn/problem/B3614

没事做了一些模板题,STL 真好用。

#include<bits/stdc++.h>
using namespace std;
int main()
{
//    freopen("input.in","r",stdin);
//    freopen("output.out","w",stdout);
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		stack<unsigned long long>a;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			string s;
			cin>>s;
			if(s=="push")
			{
				unsigned long long x;
				cin>>x;
				a.push(x);
			}
			else if(s=="pop")
			{
				if(a.empty()) printf("Empty\n");
				else a.pop();
			}
			else if(s=="query")
			{
				if(a.empty()) printf("Anguei!\n");
				else cout<<a.top()<<endl;
			}
			else if(s=="size") cout<<a.size()<<endl;
		}
	}
        return 0;
}
//栈 

B3616 【模板】队列

https://www.luogu.com.cn/problem/B3616

队列模板,我同样是用 STL 来做。

#include<bits/stdc++.h>
using namespace std;
int main()
{
//    freopen("input.in","r",stdin);
//    freopen("output.out","w",stdout);
	int n;
	cin>>n;
	queue<int>q;
	while(n--)
	{
		int t;
		cin>>t;
		if(t==1)
		{
			int x;
			cin>>x;
			q.push(x);
		}
		else if(t==2)
		{
			if(q.empty()) cout<<"ERR_CANNOT_POP"<<endl;
			else q.pop();
		}
		else if(t==3)
		{
			if(q.empty()) cout<<"ERR_CANNOT_QUERY"<<endl;
			else cout<<q.front()<<endl;
		}
		else if(t==4)
		{
			cout<<q.size()<<endl;
		}
	} 
        return 0;
}
//队列 

[AT_past202107_a] チェックディジット

https://www.luogu.com.cn/problem/AT_past202107_a

字符串基础。

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int sum=0,sum1=0;
	for(int i=0;i<s.size()-1;i++)
	{
		if((i+1)%2==1) sum+=s[i]-'0';
		else sum1+=s[i]-'0';
	}
	sum=sum*3+sum1;
	if(sum%10==(s[14]-'0')) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
        return 0;
}

标签:www,12,freopen,记录,int,cin,else,2022,模板
From: https://www.cnblogs.com/zhujiangyuan/p/2022-12_3.html

相关文章