📜  下降矩阵的实现

📅  最后修改于: 2021-05-25 21:59:45             🧑  作者: Mango

自从计算机诞生以来,好莱坞就向人们展示了一个黑客或程序员,因为他坐在计算机上键入计算机上的随机密钥,最终将其编译成模拟的Falling矩阵。在这里,我们将尝试使用C++在控制台上实现类似的降矩阵模拟。

使用C++的命令行上的Falling-Matrix

这里的想法是在定义的宽度上打印随机字符,其中两个连续的字符可能会或可能不会具有一定数量的随机定义的间隙。为了产生“下降效果”,必须在打印连续的行之间实施一定量的延迟。

// C++ program for implementation of falling matrix.
#include
#include
#include
#include
#include
#include
  
// Width of the matrix line
const int width = 70;
  
// Defines the number of flips in Boolean Array 'switches'
const int flipsPerLine =5;
  
// Delay between two successive line print
const int sleepTime = 100;
  
using namespace std;
  
int main()
{
    int i=0, x=0;
  
    // srand initialized with time function
    // to get distinct rand values at runtime
    srand(time(NULL));
  
    // Used to decide whether to print
    // the character in that particular iteration
    bool switches[width] = {0};
  
    // Set of characters to print from
    const string ch = "1234567890qwertyuiopasdfghjkl"
                      "zxcvbnm,./';[]!@#$%^&*()-=_+";
    const int l = ch.size();
  
    // Green font over black console, duh!
    system("Color 0A");
  
    // Indefinite Loop
    while (true)
    {
        // Loop over the width
        // Increment by 2 gives better effect
        for (i=0;i

这会在控制台上打印出惊人的Falling-Matrix模拟。

笔记 :

  • 由于系统已禁用,因此无法使用“在IDE上运行”按钮运行该程序。
  • 如果在编译该程序时出现编译器错误。在GCC上使用以下命令对其进行编译。
    $ g++ -std=c++11 abc.cpp -o falling.o
    $ falling.o 
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”