码迷,mamicode.com
首页 > 其他好文 > 详细

UVa153

时间:2021-01-11 10:42:34      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:==   main   ||   pre   for   函数   ios   ++   while   

这题要求 找到涂色骰子是否为相同的骰子

使用函数式编程的思想,对于第二个骰子 ,每一个面,判断将其左右旋转后能否满足第一个骰子,旋转的任务交给函数rotate去做, 而换面的操作交给f1和f2去做

#include<iostream>
#include<string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
string rotate(string s)
{
    string temp=s;
    temp[1]=s[2];
    temp[2]=s[4];
    temp[3]=s[1];
    temp[4]=s[3];
    return temp;
}
string f1(string s)
{
    string temp;
    temp.push_back(s[1]);
    temp.push_back(s[5]);
    temp.push_back(s[2]);
    temp.push_back(s[3]);
    temp.push_back(s[0]);
    temp.push_back(s[4]);
    return temp;
}
string f2(string s)
{
    string temp;
    temp.push_back(s[3]);
    temp.push_back(s[1]);
    temp.push_back(s[0]);
    temp.push_back(s[5]);
    temp.push_back(s[4]);
    temp.push_back(s[2]);
    return temp;
}
int main()
{
    string s;
    while(cin >> s){
        string s1(s.begin(), s.begin()+6), s2(s.begin()+6, s.end());
        bool flag=false;
        string a=s2, b=s2;
        for(int i=0; i<4; i++){
            for(int k=0; k<4; k++){
                a=rotate(a);
                b=rotate(b);
                if(a==s1||b==s1)  { flag=true; break; }
            }
            if(flag) break;
            a=f1(a); b=f2(b);
        }
        if(flag) cout << "TRUE" << endl;
        else cout << "FALSE" << endl;
    }
    return 0;
}

 

UVa153

标签:==   main   ||   pre   for   函数   ios   ++   while   

原文地址:https://www.cnblogs.com/ZGCblogs/p/14248282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!