Redian新闻
>
借人气问: 中国人三个字的名字,First Name 怎么写?中间有空格 (转载)
avatar
借人气问: 中国人三个字的名字,First Name 怎么写?中间有空格 (转载)# Money - 海外理财
p*o
1
请问有没有比较好的办法?我能想到的只能用stack,然后把需要的信息都存起来。但是
很麻烦,
代码写出来也不好看。
avatar
y*u
2
【 以下文字转载自 ebiz 讨论区 】
发信人: yishengheqiu (何求), 信区: ebiz
标 题: 借人气问: 中国人三个字的名字,First Name 怎么写?中间有空格没有?
发信站: BBS 未名空间站 (Thu Jun 23 23:12:52 2011, 美东)
关键是大家护照上是怎么写的?
初次来美国,办手续,首先都按护照来。比如:Zhao, Xue Hua
办驾照的时候怎么写? 写Xuehua 还是 Xue Hua ?
会不会被误认为middle name?
大家都怎么写的?
avatar
d*n
3
// test1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
void PrintArray(int *A, unsigned int N)
{
for (unsigned int i = 0; i < N; i++)
{
printf("%d ", A[i]);
}
printf("\r\n");
}
// This method print out an array iteratively.
// The idea behind this is:
// 1. Suppose we have a way to print out permutation for A[n-1].
// 2. For every permutation, insert the nth element between any of
// the n-1 elements will construct a new permuation
// F

【在 p******o 的大作中提到】
: 请问有没有比较好的办法?我能想到的只能用stack,然后把需要的信息都存起来。但是
: 很麻烦,
: 代码写出来也不好看。

avatar
p*c
4
xuehua

【在 y**********u 的大作中提到】
: 【 以下文字转载自 ebiz 讨论区 】
: 发信人: yishengheqiu (何求), 信区: ebiz
: 标 题: 借人气问: 中国人三个字的名字,First Name 怎么写?中间有空格没有?
: 发信站: BBS 未名空间站 (Thu Jun 23 23:12:52 2011, 美东)
: 关键是大家护照上是怎么写的?
: 初次来美国,办手续,首先都按护照来。比如:Zhao, Xue Hua
: 办驾照的时候怎么写? 写Xuehua 还是 Xue Hua ?
: 会不会被误认为middle name?
: 大家都怎么写的?

avatar
d*n
5
void IterativePrintPermutation2(int *A, unsigned int N)
{
int *controller = new int[N];
for (unsigned int i = 0; i < N; i++)
controller[i] = i;

while (1)
{
PrintArray(A, N);

int i = -1;
while (++i < N)
{
if (controller[i] == 0)
{
controller[i] = i;
Swap(A, i, 0);
}
else
{
Swap(A, i, controller[i]);
Swap(A,

【在 d****n 的大作中提到】
: // test1.cpp : Defines the entry point for the console application.
: //
: #include "stdafx.h"
: void PrintArray(int *A, unsigned int N)
: {
: for (unsigned int i = 0; i < N; i++)
: {
: printf("%d ", A[i]);
: }
: printf("\r\n");

avatar
r*u
6
check next_permute function in STL

【在 p******o 的大作中提到】
: 请问有没有比较好的办法?我能想到的只能用stack,然后把需要的信息都存起来。但是
: 很麻烦,
: 代码写出来也不好看。

avatar
p*o
7
老大,我看了半小时,真没看懂。。。
能否加几句注释解释一下。
我去看看next_permutation。

【在 d****n 的大作中提到】
: void IterativePrintPermutation2(int *A, unsigned int N)
: {
: int *controller = new int[N];
: for (unsigned int i = 0; i < N; i++)
: controller[i] = i;
:
: while (1)
: {
: PrintArray(A, N);
:

avatar
d*n
8
First, not sure if this is the fatest one. I did it for fun a while ago.
Hope no interviewer will ask such kind of question.
Hints:
Think about # of permutations for n size array is 1*2*3*...*(n-1)*n.
if you have permutations for 1,2,3,...(n-1). what you need to do is to
switch one of the element with the nth and repeat the permutation for length
(n-1). all the elements after (n-1)th will be untouched.

【在 p******o 的大作中提到】
: 老大,我看了半小时,真没看懂。。。
: 能否加几句注释解释一下。
: 我去看看next_permutation。

avatar
r*u
9
解释一下next_permute,其实就是按字符顺序输出,比如12345
先在的permutation是12345,下一个就是12354。
算法思路,怎么找下一个呢:
比如先在:13542,下一个是14235,
首先要从后往前找第一个pair,满足A[i]被变大的。上面这例子里这pair是35, 542已经是最大的permutation了。
所以要找到3。如果找不到这中pair,那么已经是最大的permutation了,比如54321。
然后从后往前找一个比3大的数,swap(it, 3)。这例子里是swap(4, 3)。
这样的话permutation变大,但是不会变得太大, swap(5, 3)就不对了。
先在变成14532了,然后reserve 532,得到14235。

【在 p******o 的大作中提到】
: 老大,我看了半小时,真没看懂。。。
: 能否加几句注释解释一下。
: 我去看看next_permutation。

avatar
x*r
10
这个算法我见过,很精妙哈哈

【在 r**u 的大作中提到】
: 解释一下next_permute,其实就是按字符顺序输出,比如12345
: 先在的permutation是12345,下一个就是12354。
: 算法思路,怎么找下一个呢:
: 比如先在:13542,下一个是14235,
: 首先要从后往前找第一个pair,满足A[i]: 被变大的。上面这例子里这pair是35, 542已经是最大的permutation了。
: 所以要找到3。如果找不到这中pair,那么已经是最大的permutation了,比如54321。
: 然后从后往前找一个比3大的数,swap(it, 3)。这例子里是swap(4, 3)。
: 这样的话permutation变大,但是不会变得太大, swap(5, 3)就不对了。
: 先在变成14532了,然后reserve 532,得到14235。

avatar
p*o
11
这个很通俗易懂,而且还可以handle重复的。谢谢了。

【在 r**u 的大作中提到】
: 解释一下next_permute,其实就是按字符顺序输出,比如12345
: 先在的permutation是12345,下一个就是12354。
: 算法思路,怎么找下一个呢:
: 比如先在:13542,下一个是14235,
: 首先要从后往前找第一个pair,满足A[i]: 被变大的。上面这例子里这pair是35, 542已经是最大的permutation了。
: 所以要找到3。如果找不到这中pair,那么已经是最大的permutation了,比如54321。
: 然后从后往前找一个比3大的数,swap(it, 3)。这例子里是swap(4, 3)。
: 这样的话permutation变大,但是不会变得太大, swap(5, 3)就不对了。
: 先在变成14532了,然后reserve 532,得到14235。

avatar
p*o
12
谢谢老大。

length

【在 d****n 的大作中提到】
: First, not sure if this is the fatest one. I did it for fun a while ago.
: Hope no interviewer will ask such kind of question.
: Hints:
: Think about # of permutations for n size array is 1*2*3*...*(n-1)*n.
: if you have permutations for 1,2,3,...(n-1). what you need to do is to
: switch one of the element with the nth and repeat the permutation for length
: (n-1). all the elements after (n-1)th will be untouched.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。