夏洛克


私信TA

用户名:SherlockObama

访问量:12454

签 名:

SherlockObama

等  级
排  名 1035
经  验 3165
参赛次数 0
文章发表 17
年  龄 0
在职情况 学生
学  校 湖北文理学院
专  业 计算机

  自我简介:

Go Go Go!!!

解题思路: 1.暴力法  2.(大神的)  STL组合法

注意事项:

参考代码:先看下我的无脑暴力。。。  直接打表

   

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
char a[4]={'a','b','c','d'};
int main(){
    string s;
    while(cin>>s){
    if(s=="abcd")  cout<<"0"<<endl;
    if(s=="abdc")  cout<<"1"<<endl;
    if(s=="acbd")  cout<<"2"<<endl;
    if(s=="acdb")  cout<<"3"<<endl;
    if(s=="adbc")  cout<<"4"<<endl;
    if(s=="adcb")  cout<<"5"<<endl;
    if(s=="bacd")  cout<<"6"<<endl;
    if(s=="badc")  cout<<"7"<<endl;
    if(s=="bcad")  cout<<"8"<<endl;
    if(s=="bcda")  cout<<"9"<<endl;
    if(s=="bdac")  cout<<"10"<<endl;
        if(s=="bdca")  cout<<"11"<<endl;
   if(s=="cabd")  cout<<"12"<<endl;
    if(s=="cadb")  cout<<"13"<<endl;
    if(s=="cbad")  cout<<"14"<<endl;
    if(s=="cbda")  cout<<"15"<<endl;
    if(s=="cdab")  cout<<"16"<<endl;
    if(s=="cdba")  cout<<"17"<<endl;
    if(s=="dabc")  cout<<"18"<<endl;
    if(s=="dacb")  cout<<"19"<<endl;
    if(s=="dbac")  cout<<"20"<<endl;
    if(s=="dbca")  cout<<"21"<<endl;
    if(s=="dcab")  cout<<"22"<<endl;
    if(s=="dcba")  cout<<"23"<<endl;
   
    }
return 0;}
          接下来咱们看看一个大神的思路。。  帮他宣传下   STL妙用!
#include<bits/stdc++.h>
using namespace std;
 
int main() {
    int count = 0;
    char str[12], copy[12];
    cin >> str;
    /*          复制输入的字符串           */
    memcpy(copy, str, sizeof(str) * sizeof(char));
    /*         排序回到最初的状态          */
    sort(str, str + strlen(str));
    /*        如果字符串相等就退出         */
    while (strcmp(str, copy)) {
        count++;
        /*           生成下一个排列            */
        next_permutation(str, str + strlen(str));
    }
    cout << count << endl;
    return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区