2024.3.23蓝桥杯小白入门赛

第二题: 

链接: 

https://www.lanqiao.cn/problems/17035/learning/?contest_id=177

我太菜了,不会写,只能看题解

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(string a ,string b)
{
  return a+b<b+a;
} 
int main()
{
  ll n;
  cin>>n;
  vector<string>s;
  for(ll i=1;i<=n;i++)
  {
    string s1;
    cin>>s1;
    s.push_back(s1);
  }
  sort(s.begin(),s.end(),solve);
  for(ll i=0;i<n;i++)cout<<s[i];
}

第三题:

链接:https://www.lanqiao.cn/problems/17028/learning/?contest_id=177 

方法一: 

//找规律
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
  string s;
	ll T;
	cin>>T;
	while(T--)
	{
		cin>>n>>s;
		n%=10;
    ll sum=s[s.size()-1]-'0'+(s[s.size()-2]-'0')*10;
    ll x=0,p=sum;
    x=s[s.size()-1]-'0';
    x%=2;
		p%=4;
		if(n==1||n==5||n==6||n==0)
		{
			cout<<n<<endl;
		}
		else if(n==2)
		{
			if(p==1)cout<<2<<endl;
			else if(p==2)cout<<4<<endl;
			else if(p==3)cout<<8<<endl;
			else cout<<6<<endl;
		}
		else if(n==3)
		{
			if(p==1)cout<<3<<endl;
			else if(p==2)cout<<9<<endl;
			else if(p==3)cout<<7<<endl;
			else cout<<1<<endl;
		}
		else if(n==7)
		{
			if(p==1)cout<<7<<endl;
			else if(p==2)cout<<9<<endl;
			else if(p==3)cout<<3<<endl;
			else cout<<1<<endl;
		}
		else if(n==8)
		{
			if(p==1)cout<<8<<endl;
			else if(p==2)cout<<4<<endl;
			else if(p==3)cout<<2<<endl;
			else cout<<6<<endl;
		}else if(n==4)
		{
			if(x==1)cout<<4<<endl;
			else cout<<6<<endl;
		}
		else if(n==9)
		{
			if(x==1)cout<<9<<endl;
			else cout<<1<<endl;
		}
	}

}

 方法二:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+10;
ll quick(ll x,string p)
{
  ll res=1;
  x%=10;
  for(ll i=p.size()-1;i>=0;i--)
  {
    ll digit=p[i]-'0';//相当于将要求的一个指数拆分成多个指数相乘(应该是)
    ll temp=1;
    for(ll j=0;j<digit;j++)
    {
      temp=temp*x%10;
    }
    res=res*temp%10;
    x=x*x%10;
  }
  return res;
}
int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
    string s;
    ll x;
    cin>>x>>s;
    cout<<quick(x,s)<<endl;
  }
}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值