죄송한데 C++ 문제 좀

  • #3374331
    12345 69.***.33.212 1092

    혼자 보고 있는데 이해가 안가는 부분이 있습니다.

    문제: Many web sites and software packages require you to create passwords that contain at least one digit and one special character. Your task is to write a program that generates such a password of a given length. The characters should be chosen randomly.

    1. We will write a password-generating function and call it from the program’s main function. We could include multiple digits and special characters, but for simplicity, we decide to include just one of each. We need to decide which special characters are valid. For our solution, we will use the following set:
    + – * / ? ! @ # $ % &
    we will use only lowercase letters in the English alphabet.

    2.There is just one parameter: the length of the password.
    ( 해결됨: the length of the password 를 입력값으로 잡아주는지….)

    3.string make_password(int length)

    4.Make an empty string called password.
    Randomly generate length – 2 letters and append them to password. (해결됨:여기서 왜 이렇게 되는지 ….)
    Randomly generate a digit and insert it at a random location in password.
    Randomly generate a symbol and insert it at a random location in password.

    5.

    /**
    Returns a string containing one character randomly chosen from a given string.
    @param characters the string from which to randomly choose a character
    @return a substring of length 1, taken at a random index (왜 substring of length1 이 되는지….)
    */
    string random_character(string characters)

    (여기서부터는 좀 도움이 필요합니다)
    /**
    Inserts one string into another at a random position.
    @param str the string into which another string is inserted
    @param to_insert the string to be inserted
    @return the result of inserting to_insert into str
    */
    string insert_at_random(string str, string to_insert)
    Now we can translate the pseudocode of Step 4 into C++:

    string make_password(int length)
    {
    string password = “”; ( 해결됨: 여기서 왜 이렇게 잡아주나요?)
    for (int i = 0; i < length – 2; i++) (해결됨: i=0, i++,이건 알겠는데 i < length – 2 이 부분은 어떻게 이해해야 하는지…)

    {
    password = password + random_character(“abcdefghijklmnopqrstuvwxyz”);
    }
    string random_digit = random_character(“0123456789”);
    password = insert_at_random(password, random_digit);
    string random_symbol = random_character(“+-*/?!@#$%&”);
    password = insert_at_random(password, random_symbol);
    return password;
    }

    미리 감사합니다.

    • Slim 192.***.54.44

      숫자 1개와 특수문자 1개가 무조건 들어가야 되니까. 그 공간을 안배해서 -2 하는겁니다.

    • KoreanBard 4.***.46.242

      알파벳 lower character 로 대충 잡아 놓고 (특수 캐릭), (숫자) 넣으려고 첨에 만들 때 길이를 -2 한거네요.

    • 1234 104.***.0.77

      이건 영어가 부족한건지 cs 기본이 부족한건지 총체적 난국이네염…

      과외선생같이 누군가 달라붙어서 지도받아야 할 수준인데..

      암튼 다른건 윗분들이 대답해주셨고,

      @return a substring of length 1, taken at a random index (왜 substring of length1 이 되는지….)

      substring of length 1 의 영어 의미는 알고 있다는 전제하에,
      이건 random_character() function 자체가 요구하는게 input string 에서 character 하나 빼오는게 요구사항이라 그럼.