本地可以,but满江红

P5730 【深基5.例10】显示屏

_xjx_ @ 2024-12-08 19:05:33

// 002.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "bits/stdc++.h"
using namespace std;
int main(){  
    short n = 0;
    cin >> n;
    char a[100]{};
    int b[100]{};
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        switch (a[i]) {
        case '0':
            cout << "XXX.";
            break;
        case '1':
            cout << "..X.";
            break;
        case '2':
            cout << "XXX.";
            break;
        case '3':
            cout << "XXX.";
            break;
        case '4':
            cout << "X.X.";
            break;
        case '5':
            cout << "XXX.";
            break;
        case '6':
            cout << "XXX.";
            break;
        case '7':
            cout << "XXX.";
            break;
        case '8':
            cout << "XXX.";
            break;
        case '9':
            cout << "XXX.";
            break;
        }
    }
    cout << "\b \r\n";
    for (int i = 0; i < n; i++) {
        switch (a[i]) {
        case '0':
            cout << "X.X.";
            break;
        case '1':
            cout << "..X.";
            break;
        case '2':
            cout << "..X.";
            break;
        case '3':
            cout << "..X.";
            break;
        case '4':
            cout << "X.X.";
            break;
        case '5':
            cout << "X...";
            break;
        case '6':
            cout << "X...";
            break;
        case '7':
            cout << "..X.";
            break;
        case '8':
            cout << "X.X.";
            break;
        case '9':
            cout << "X.X.";
            break;
        }
    }
    cout << "\b \r\n";
    for (int i = 0; i < n; i++) {
        switch (a[i]) {
        case '0':
            cout << "X.X.";
            break;
        case '1':
            cout << "..X.";
            break;
        case '2':
            cout << "XXX.";
            break;
        case '3':
            cout << "XXX.";
            break;
        case '4':
            cout << "XXX.";
            break;
        case '5':
            cout << "XXX.";
            break;
        case '6':
            cout << "XXX.";
            break;
        case '7':
            cout << "..X.";
            break;
        case '8':
            cout << "XXX.";
            break;
        case '9':
            cout << "XXX.";
            break;
        }
    }
    cout << "\b \r\n";
    for (int i = 0; i < n; i++) {
        switch (a[i]) {
        case '0':
            cout << "X.X.";
            break;
        case '1':
            cout << "..X.";
            break;
        case '2':
            cout << "X...";
            break;
        case '3':
            cout << "..X.";
            break;
        case '4':
            cout << "..X.";
            break;
        case '5':
            cout << "..X.";
            break;
        case '6':
            cout << "X.X.";
            break;
        case '7':
            cout << "..X.";
            break;
        case '8':
            cout << "X.X.";
            break;
        case '9':
            cout << "..X.";
            break;
        }
    }
    cout << "\b \r\n";
    for (int i = 0; i < n; i++) {
        switch (a[i]) {
        case '0':
            cout << "XXX.";
            break;
        case '1':
            cout << "..X.";
            break;
        case '2':
            cout << "XXX.";
            break;
        case '3':
            cout << "XXX.";
            break;
        case '4':
            cout << "..X.";
            break;
        case '5':
            cout << "XXX.";
            break;
        case '6':
            cout << "XXX.";
            break;
        case '7':
            cout << "..X.";
            break;
        case '8':
            cout << "XXX.";
            break;
        case '9':
            cout << "XXX.";
            break;
        }
    }
    cout << "\b \r\n";
    return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

VS自带注释,请不要关注


by hyclol @ 2024-12-08 19:32:17

换行试试用

cout << "\n";

by _xjx_ @ 2024-12-08 19:46:52

@hyclol\n 不行,linux要\r\n


by HuangSiHan3116 @ 2024-12-08 20:31:55

@xjx写那么长干嘛?可以用字符串。

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
string s[9]={"\0"},s2;
signed main(){
    char a;
    scanf("%lld",&n);
    cin>>s2;
    for(int i=0;i<n;i++){
        if(s2[i]=='0'){
            s[0]+="XXX",s[1]+="X.X",s[2]+="X.X",s[3]+="X.X",s[4]+="XXX";
        }else if(s2[i]=='1'){
            s[0]+="..X",s[1]+="..X",s[2]+="..X",s[3]+="..X",s[4]+="..X";
        }else if(s2[i]=='2'){
            s[0]+="XXX",s[1]+="..X",s[2]+="XXX",s[3]+="X..",s[4]+="XXX";
        }else if(s2[i]=='3'){
            s[0]+="XXX",s[1]+="..X",s[2]+="XXX",s[3]+="..X",s[4]+="XXX";
        }else if(s2[i]=='4'){
            s[0]+="X.X",s[1]+="X.X",s[2]+="XXX",s[3]+="..X",s[4]+="..X";
        }else if(s2[i]=='5'){
            s[0]+="XXX",s[1]+="X..",s[2]+="XXX",s[3]+="..X",s[4]+="XXX";
        }else if(s2[i]=='6'){
            s[0]+="XXX",s[1]+="X..",s[2]+="XXX",s[3]+="X.X",s[4]+="XXX";
        }else if(s2[i]=='7'){
            s[0]+="XXX",s[1]+="..X",s[2]+="..X",s[3]+="..X",s[4]+="..X";
        }else if(s2[i]=='8'){
            s[0]+="XXX",s[1]+="X.X",s[2]+="XXX",s[3]+="X.X",s[4]+="XXX";
        }else if(s2[i]=='9'){
            s[0]+="XXX",s[1]+="X.X",s[2]+="XXX",s[3]+="..X",s[4]+="XXX";
        }
        if(i!=n-1) s[0]+=".",s[1]+=".",s[2]+=".",s[3]+=".",s[4]+=".";   
    }
    for(int i=0;i<5;i++) cout<<s[i]<<endl;
    return 0;
}

求关注。


|