UVa 146 ID码

题意:输出一个排列的后继排列,如果是最大的降序排列,则输出没有后继。

思路:调用STL中的next_permutation()函数即可。不过这个函数在求后继时是一个循环状态,即全升序是全降序的后继,循环回来了。所以在调用之前判断一下是否为全降序序列即可。       感觉用这个函数没什么技术含量,有时间用纯C写一个。

Code:

#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

char code[70];

int main()
{
  while(scanf("%s",code)==1 && code[0]!='#')
  {
    int len=strlen(code);
    bool flag=1;//是否为降序
    for(int i=0;i<len-1;++i)
      if(code[i]<code[i+1]) { flag=0; break;}
    if(flag) printf("No Successor\n");
    else
    {
      next_permutation(code,code+strlen(code));
      printf("%s\n",code);
    }
  }
  return 0;
}
时间: 2024-07-28 20:34:52

UVa 146 ID码的相关文章

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

Brute Force &amp; 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来实现就可.自己手动写了一个,并不复杂.

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 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()

ID Codes UVA 146(求字典序比当前字符串小的最大字符串)

说说: 题意其实很简单,就是给你一个由小写英文字母组成的字符串,然后让你求字典序比当前字符串小的最大的字符串.解法的话,就是从字符串的末尾开始遍历,若得到的子串已经是该字串所能得到的最小字典序,则继续往前遍历.否则,先在子串中,找到比原字串的首字符小的最大字符,将两者交换位置.然后将除首字符以外的其他字串排列获取最大字典序的子串即可.具体方案,看源代码好了. 源代码: #include <stdio.h> #include <string.h> #define MAX 50+5 c

获取唯一ID码

坑逼的安卓厂商太多,没有可以可靠获取所有厂商设备唯一ID的方法,各个方法都有自己的使用范围和局限性, 这也是目前流行的Android系统版本过多,设备也是来自不同厂商,且没有统一标准等原因造成的. 比较常用的有: 1.DEVICE_ID TelephonyManager tm =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);String DEVICE_ID = tm.getDeviceId(); 根据不同的手机设备返回

iphone5解锁激活id码iphone5S解锁激活+q:2100997525

百度官网认证QQ[百度唯一认证QQ:2100997525]专业破解苹果ID ,手机微信,手机号码监听,破译陌陌,QQ, 短信内容查询删除 开房登记记录 通话清单  QQ聊天记录查询删除 密码破解 邮箱以及各种聊天记录恢复与删除查询[百 度唯一认证QQ:2100997525]专业手机定位,通话清单,知己知彼,百战百胜,网站入侵等其他业务 ▌是您值得信赖的 怎么偷看別人的QQ聊天記錄?[百度唯一認証QQ:2100997525]專業破解苹果id.手机微信,破譯陌陌,QQ,郵箱以及各 種聊天記錄恢復與查