题目
代码
第一题
| #include <iostream> |
| using namespace std; |
| |
| |
| int digital_root(int n) { |
| while (n >= 10) { |
| n = n / 10 + n % 10; |
| } |
| return n; |
| } |
| |
| int main() { |
| int i; |
| int j; |
| int a[20][20]; |
| char b[20][20]; |
| for (i = 0; i < 9; i++) { |
| for (j = 0; j < 9; j++) { |
| a[i][j] = digital_root((i + 1) * (j + 1)); |
| } |
| } |
| for (i = 0; i < 9; i++) { |
| for (j = 0; j < 9; j++) { |
| cout << a[i][j] << " "; |
| } |
| cout << endl; |
| } |
| int n; |
| cout << "Please enter a integer range 1-9: "; |
| cin >> n; |
| cout << "Look, vedic stars!" << endl; |
| for (i = 0; i < 9; i++) { |
| for (j = 0; j < 9; j++) { |
| if (a[i][j] == n) { |
| b[i][j] = '*'; |
| } else { |
| b[i][j] = ' '; |
| } |
| } |
| } |
| for (i = 0; i < 9; i++) { |
| for (j = 0; j < 9; j++) { |
| cout << b[i][j] << " "; |
| } |
| cout << endl; |
| } |
| return 0; |
| } |
第二题
| #include <iostream> |
| #include <string> |
| using namespace std; |
| |
| struct elevator { |
| int time = 0; |
| string calculation; |
| }ele[100]; |
| |
| int main() { |
| int n; |
| int number = 0; |
| while (cin >> n && n != 0) { |
| int now = 0; |
| int next = 0; |
| for (int i = 0; i < n; i++) { |
| cin >> next; |
| if (now < next) { |
| ele[number].time += (next - now) * 6 + 5; |
| if (i != 0) { |
| ele[number].calculation.append("+"); |
| } |
| ele[number].calculation.append("6*" + to_string(next - now) + "+5"); |
| } else { |
| ele[number].time += (now - next) * 4 + 5; |
| if (i != 0) { |
| ele[number].calculation.append("+"); |
| } |
| ele[number].calculation.append("4*" + to_string(now - next) + "+5"); |
| } |
| now = next; |
| } |
| if (n != 0) { |
| number++; |
| } |
| } |
| for (int i = 0; i < number; i++) { |
| cout << ele[i].time << "(" << ele[i].calculation << ")" << endl; |
| } |
| return 0; |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现