Brute Force & STL --- UVA 146 ID Codes

 ID Codes 

Problem‘s Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=3&problem=82&mosmsg=Submission+received+with+ID+14418598



Mean:

求出可重排列的下一个排列。

analyse:

直接用STL来实现就可。自己手动写了一个,并不复杂。

Time complexity: O(n^2)

Source code: 

1.STL

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    char s[55];
    while(scanf("%s",s)!=EOF)
    {
        if(s[0]==‘#‘) break;
        if(next_permutation(s,s+strlen(s))) printf("%s\n",s);
        else printf("No Successor\n");
        memset(s,0,sizeof(s));
    }
    return 0;
}

2.手写

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    //freopen("a.txt","r",stdin);
    char s[55];
    while(scanf("%s",s),s[0]!=‘#‘)
    {
        int i,j,len(strlen(s)); //   涨姿势了
        for(i=len-2; i>=0; i--)
            if(s[i]<s[i+1])
                break;
        if(i<0) puts("No Successor");
        else
        {
            for(j=i+1; i<len; j++)
                if(s[i]>=s[j])
                {
                    char c=s[i];
                    s[i]=s[j-1];
                    s[j-1]=c;
                    break;
                }
            sort(s+i+1,s+len);
            puts(s);
        }
    }
    return 0;
}

  

时间: 2024-10-09 00:39:10

Brute Force & STL --- UVA 146 ID Codes的相关文章

UVA - 146 - ID Codes (枚举排列)

UVA - 146 ID Codes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exercise greater control over its ci

UVA 146 ID Codes(下一个排列)

C - ID Codes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Appoint description:  System Crawler  (2014-05-12) Description  ID Codes  It is 2084 and the year of Big Brother has finally arrived, albeit a century l

UVA 146 ID Codes

求用这些字母的下一个排列是什么.直接使用C++ STL库里面的next_permutation #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { char s[1000]; while (~scanf("%s", s)) { if (strcmp(s, "#") == 0) break; int y =

uva 146 ID Codes(求下一个排列)水水水

分别利用STL中的next_permutation和它的实现原理来写: next_permutation: <span style="font-family:Courier New;font-size:18px;">#include<stdio.h> #include<stdlib.h> #include<string.h> #include<algorithm> using namespace std; int main()

UVA 146 ID code(next_permutation的运用)

ID code It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exercise greater control over its citizens and thereby to counter a chronic breakdown in law and order, the Government decides on a radical measure

UVa 146 ID码

题意:输出一个排列的后继排列,如果是最大的降序排列,则输出没有后继. 思路:调用STL中的next_permutation()函数即可.不过这个函数在求后继时是一个循环状态,即全升序是全降序的后继,循环回来了.所以在调用之前判断一下是否为全降序序列即可.       感觉用这个函数没什么技术含量,有时间用纯C写一个. Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace

小白日记46:kali渗透测试之Web渗透-SqlMap自动注入(四)-sqlmap参数详解- Enumeration,Brute force,UDF injection,File system,OS,Windows Registry,General,Miscellaneous

sqlmap自动注入 Enumeration[数据枚举] --privileges -U username[CU 当前账号] -D dvwa -T users -C user --columns  [指定数据库,表,列] --exclude-sysdbs [排除系统层的库] ******************************************************************************* #查具体数据 [前提:当前数据库用户有权读取informatio

HDU 4971 A simple brute force problem.

A simple brute force problem. Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 497164-bit integer IO format: %I64d      Java class name: Main There's a company with several projects to be done. Finish a projec

字符串处理------Brute Force与KMP

一,字符串的简单介绍 例:POJ1488  http://poj.org/problem?id=1488 题意:替换文本中的双引号: #include <iostream> #include <cstring> #include <cstdio> using namespace std; int main() { char c,flag=1; //freopen("Atext.in","r",stdin); while((c=ge