论输出 hello world 的N种方法...

发布时间 2023-10-06 19:56:06作者: shixuanbin

RT

第1种:

#include<bits/stdc++.h>
using namespace std;
int main() 
{
    cout << "Hello,World!" << endl;
    return 0;
}

第2种:

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iterator>
#include <algorithm>

int main() {
    std::map<char, std::vector<std::string>> characters;

    characters['H'] = {"*   *", "*   *", "*****", "*   *", "*   *"};
    characters['e'] = {"*****", "*    ", "*****", "*    ", "*****"};
    characters['l'] = {"*    ", "*    ", "*    ", "*    ", "*****"};
    characters['o'] = {"*****", "*   *", "*   *", "*   *", "*****"};
    characters[','] = {"      ", "      ", "      ", "  **  ", " **   "};
    characters[' '] = {"      ", "      ", "      ", "      ", "      "};
    characters['W'] = {"*   *", "*   *", "*****", "* * *", "*   *"};
    characters['r'] = {"* *  ", "*  * ", "*  * ", "* *  ", "*   *"};
    characters['d'] = {"     ", "     ", "*****", "*   *", "*****"};

    std::string hello = "Hello, World!";

    for (int i = 0; i < 5; ++i) {
        for (char c : hello) {
            std::vector<std::string> lines = characters[c];
            for (const std::string& line : lines) {
                std::cout << line << "  ";
            }
        }
        std::cout << std::endl;
    }

    return 0;
}

第3种:

#include <iostream>
#include <string>

// 凯撒密码加密函数
std::string caesarCipher(const std::string& text, int shift) {
    std::string encryptedText = "";
    for (char c : text) {
        if (isalpha(c)) {
            char base = (isupper(c)) ? 'A' : 'a';
            encryptedText += char(((c - base + shift) % 26) + base);
        } else {
            encryptedText += c;
        }
    }
    return encryptedText;
}

int main() {
    std::string message = "Hello, World!";
    int shift = 3;  // 替换的位移量

    std::string encryptedMessage = caesarCipher(message, shift);

    std::cout <<  encryptedMessage << std::endl;

    return 0;
}

第4种:

#include <iostream>
#include <string>

int main() {
    std::string greeting = "Hello, World!";
    for (int i = 0; i < greeting.length(); ++i) {
        char character = greeting[i];
        for (int j = 0; j < 8; ++j) {
            int bit = (character >> (7 - j)) & 1;
            if (bit) {
                std::cout << "*";
            } else {
                std::cout << " ";
            }
        }
        std::cout << std::endl;
    }
    return 0;
}

第5种:

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>

void say() {
    puts("Hello world!");
    exit(0);
}

int main() {
    volatile intptr_t a = 0;
    volatile intptr_t * p = &a;

    *(p + 2) = (intptr_t)say;
    *(p + 3) = (intptr_t)say;

    return 0;
}

第6种:

#include <stdio.h>

void alien_say(char * p) {
    while (putchar(*(p += *(p + 1) - *p)));
}

int main() {
    return alien_say("BETHO! Altec oh liryom(a loadjudas!) dowd."), 0;
}

未完待续