蔡徐坤打篮球代码c语音
时间: 2023-11-12 14:55:13 浏览: 457
蔡徐坤打篮球的C语言代码如下所示:
#include <iostream>
#include <string>
#include <chrono>
#include <thread>
using namespace std;
int main() {
string name = "蔡徐坤";
string ball = "O";
int ball_pos = 0;
int direction = 1;
int name_pos = 0;
int name_direction = 1;
int count = 0;
while (true) {
// 输出球和名字
for (int i = 0; i < ball_pos; i++) {
cout << " ";
}
cout << ball << endl;
for (int i = 0; i < name_pos; i++) {
cout << " ";
}
cout << name << endl;
// 更新球的位置
ball_pos += direction;
if (ball_pos == 0 || ball_pos == 70) {
direction = -direction;
}
// 更新名字的位置
name_pos += name_direction;
if (name_pos == 0 || name_pos == 70 - name.size()) {
name_direction = -name_direction;
}
// 计数器
count++;
if (count == 10) {
count = 0;
name = name.substr(1) + name;
}
// 清空屏幕
system("cls");
}
return 0;
}
阅读全文