使用须知:测试机为 Mac,windows 下可能会需要修改
- 代码使用了 usleep(),若为 windows 可能需要修改
- 先上效果图(牛是用 cowsay 生成的)
#include#include #define ALLPE "" #define TREE "" #define DOOR "" char content[10][32] = { " _________________ ", "< Merry Christmas >", " ----------------- ", " \ ^__^", " \ (oo)\_______", " (__)\ )\/\", " ||----w |", " || ||" }; int m; // 输出第 n 层,注意索引从 1 开始 void printRowLine(int n) { int bottomNum = 1 + (5 * n - 1) * 2; int topNum = bottomNum - 12; for (int i = topNum; i <= bottomNum; i += 2) { if (n == 1 && i == 1) { for (int j = 0; j < ((1 + (5 * m - 1) * 2) - i) / 2; j++) printf(" "); printf("%sn", ALLPE); continue; } for (int j = 0; j < ((1 + (5 * m - 1) * 2) - i) / 2; j++) printf(" "); for (int j = 0; j < i; j++) printf("%s", TREE); printf("n"); usleep(50000); } } // 输出树身 void showHead(int n) { m = n; for (int i = 1; i <= m; i++) printRowLine(i); } // 输出尾部 void printFoot() { for (int i = 0; i < 8; ++i) { usleep(50000); for (int j = 0; j < ((1 + (5 * m - 1) * 2) - 5) / 2; j++) printf(" "); for (int j = 0; j < 5; j++) printf("%s", DOOR); for (int j = 0; j < 15; j++) printf(" "); printf("%s", content[i]); printf("n"); } } int main() { showHead(2); printFoot(); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)