A-签到题
签到题思路
在堆的底端填入一个T之后开始读入,当现在的堆顶元素为S读入为T时就弹出,循环,最后输出堆的元素数量减1.注意不要读入‘\n’。
代码如下
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<char> q;
q.push_back('T');
char c;
while(scanf("%c",&c)!=EOF)
{
if(c=='\n') continue;
if(c=='T'&&*(q.end()-1)=='S')
{
q.pop_back();
continue;
}
else
{
q.push_back(c);
}
}
cout<<q.size()-1;
}
B-转魔方
思路分析
四种情况:考虑二阶魔方只要一面时完整的那他的对面也是完整的
1.前后面相同
2.左右面相同
3.上下面相同
4.所有面相同
用一个长度为4的数组,存储需要扭转的面的数值,错位对比是否相等
代码如下:
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int shang[3][3],xia[3][3],qian[3][3],hou[3][3],zuo[3][3],you[3][3];
bool input()
{
bool a = false,b= false,c = false,d = false,e = false,f = false;;
int kuai1,kuai2,kuai3,kuai4;
scanf("%d%d%d%d",&kuai1,&kuai2,&kuai3,&kuai4);
//判断是否满足
//1 1 或者 1 2 或者 1 1
//2 2 1 2 1 1
if((kuai1 == kuai2 && kuai3 == kuai4)||(kuai1 == kuai3 && kuai2 == kuai4))
{
shang[1][1] = kuai1; shang[1][2] = kuai2; shang[2][1] = kuai3; shang[2][2] = kuai4;
a = true;
}
scanf("%d%d%d%d",&kuai1,&kuai2,&kuai3,&kuai4);
if((kuai1 == kuai2 && kuai3 == kuai4)||(kuai1 == kuai3 && kuai2 == kuai4))
{
qian[1][1] = kuai1; qian[1][2] = kuai2; qian[2][1] = kuai3; qian[2][2] = kuai4;
b = true;
}
scanf("%d%d%d%d",&kuai1,&kuai2,&kuai3,&kuai4);
if((kuai1 == kuai2 && kuai3 == kuai4)||(kuai1 == kuai3 && kuai2 == kuai4))
{
xia[1][1] = kuai1; xia[1][2] = kuai2; xia[2][1] = kuai3; xia[2][2] = kuai4;
c = true;
}
scanf("%d%d%d%d",&kuai1,&kuai2,&kuai3,&kuai4);
if((kuai1 == kuai2 && kuai3 == kuai4)||(kuai1 == kuai3 && kuai2 == kuai4))
{
hou[1][1] = kuai1; hou[1][2] = kuai2; hou[2][1] = kuai3; hou[2][2] = kuai4;
d = true;
}
scanf("%d%d%d%d",&kuai1,&kuai2,&kuai3,&kuai4);
if((kuai1 == kuai2 && kuai3 == kuai4)||(kuai1 == kuai3 && kuai2 == kuai4))
{
zuo[1][1] = kuai1; zuo[1][2] = kuai2; zuo[2][1] = kuai3; zuo[2][2] = kuai4;
e = true;
}
scanf("%d%d%d%d",&kuai1,&kuai2,&kuai3,&kuai4);
if((kuai1 == kuai2 && kuai3 == kuai4)||(kuai1 == kuai3 && kuai2 == kuai4))
{
you[1][1] = kuai1; you[1][2] = kuai2; you[2][1] = kuai3; you[2][2] = kuai4;
f = true;
}
return a&b&c&d&e&f;
}
int judge()
{
if((shang[1][1] == shang[1][2]&& shang[1][1]==shang[2][1])&&
(xia[1][1] == xia[1][2]&& xia[1][1]==xia[2][1])&&
(zuo[1][1] == zuo[1][2]&& zuo[1][1]==zuo[2][1])&&
(you[1][1] == you[1][2]&& you[1][1]==you[2][1])&&
(qian[1][1] == qian[1][2]&& qian[1][1]==qian[2][1])&&
(hou[1][1] == hou[1][2]&& hou[1][1]==hou[2][1]))
{
return 4;
}
if(zuo[1][1] == zuo[1][2]&& zuo[1][1]==zuo[2][1])
{
return 1;
}
if(shang[1][1] == shang[1][2]&& shang[1][1]==shang[2][1])
{
return 2;
}
if(qian[1][1] == qian[1][2]&& qian[1][1]==qian[2][1])
{
return 3;
}
}
void solve()
{
int k = judge();
int a[4],b[4];
//1代表左右两个面相同,则前后扭
if(k == 1)
{
a[0] = shang[1][1],b[0] = shang[1][2];
a[1] = qian[1][1] ,b[1] = qian[1][2];
a[2] = xia[1][1] ,b[2] = xia[1][2];
a[3] = hou[1][1] ,b[3] = hou[1][2];
if(a[0]==b[1]&&a[1]==b[2]&&a[2]==b[3]&&a[3]==b[0])cout<<"YES"<<endl;
else if(b[0]==a[1]&&b[1]==a[2]&&b[2]==a[3]&&b[3]==a[0])cout<<"YES"<<endl;
else{
cout<<"NO"<<endl;
}
}
//上下相同
if(k == 2)
{
a[0] = qian[1][1],b[0] = qian[2][1];
a[1] = you[2][1] ,b[1] = you[2][2];
a[2] = hou[2][2] ,b[2] = hou[1][2];
a[3] = zuo[1][2] ,b[3] = zuo[1][1];
if(a[0]==b[1]&&a[1]==b[2]&&a[2]==b[3]&&a[3]==b[0])cout<<"YES"<<endl;
else if(b[0]==a[1]&&b[1]==a[2]&&b[2]==a[3]&&b[3]==a[0])cout<<"YES"<<endl;
else{
cout<<"NO"<<endl;
}
}
//前后相同
if(k == 3)
{
a[0] = shang[1][1],b[0] = shang[2][1];
a[1] = you[1][1] ,b[1] = you[2][1];
a[2] = xia[2][1] ,b[2] = xia[1][1];
a[3] = zuo[1][1] ,b[3] = zuo[2][1];
if(a[0]==b[1]&&a[1]==b[2]&&a[2]==b[3]&&a[3]==b[0])cout<<"YES"<<endl;
else if(b[0]==a[1]&&b[1]==a[2]&&b[2]==a[3]&&b[3]==a[0])cout<<"YES"<<endl;
else{
cout<<"NO"<<endl;
}
}
if(k == 4)
{
cout<<"YES"<<endl;
return;
}
}
int main()
{
int N;
cin>>N;
while(N--)
{
if(!input())
{
cout<<"NO"<<endl;
continue;
}
solve();
}
}