大佬们,C++全WA求助

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

Amron @ 2024-02-01 12:11:55

看了其他讨论改了scanf,但是还是不对。 因为我的方法用了\033来控制光标,想问下是不是不能用这个方法呀(本地测试是对的)

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
    int n;
    scanf("%d\n", &n);

    char num[105];
    for (int i = 0; i < n; ++i)
    {
        cin >> num[i];
    }

    printf("\n\n\n\n\n");
    int i = 0;
    while (i < n)
    {
        switch (num[i] - '0')
        {
        case 0:
            printf("\033[5A");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("X.X"); printf("\033[1B\033[3D");
            printf("X.X"); printf("\033[1B\033[3D");
            printf("X.X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D"); break;
        case 1:
            printf("\033[5A");
            printf("..X"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D"); break;
        case 2:
            printf("\033[5A");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("X.."); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D"); break;
        case 3:
            printf("\033[5A");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D"); break;
        case 4:
            printf("\033[5A");
            printf("X.X"); printf("\033[1B\033[3D");
            printf("X.X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D"); break;
        case 5:
            printf("\033[5A");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("X.."); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D"); break;
        case 6:
            printf("\033[5A");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("X.."); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("X.X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D"); break;
        case 7:
            printf("\033[5A");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D"); break;
        case 8:
            printf("\033[5A");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("X.X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("X.X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D"); break;
        case 9:
            printf("\033[5A");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("X.X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D");
            printf("..X"); printf("\033[1B\033[3D");
            printf("XXX"); printf("\033[1B\033[3D"); break;
        }

        if (i != n - 1)
        {
            printf("\033[5A\033[3C");
            for (int k = 0; k < 5; ++k)
            {
                printf("."); printf("\033[1B\033[1D");
            }
        }
        printf("\033[1C");

        ++i;
    }

    return 0;
}

by yuyc @ 2024-02-01 12:36:57

我用洛谷在线IDE测了下,不行


by Amron @ 2024-02-02 10:06:33

@yuyc 我在VS上运行倒是没问题,还是用其他方法吧。谢谢大佬


by Tom2 @ 2024-07-04 21:57:46

#include <bits/stdc++.h>
using namespace std;

string num;

void ifcout1(char x){
    if(x == '0' || x == '2' || x == '3' || x == '5' || x == '6' || x == '7' || x == '8' || x == '9'){
        cout << "XXX";
    }
    if(x == '1'){
        cout << "..X";
    }
    if(x == '4'){
        cout << "X.X";
    }
}
void ifcout2(char x){
    if(x == '0' || x == '4' || x == '8' || x == '9'){
        cout << "X.X";
    }
    if(x == '1' || x == '2' || x == '3' || x == '7'){
        cout << "..X";
    }
    if(x == '5' || x == '6'){
        cout << "X..";
    }
}
void ifcout3(char x){
    if(x == '0'){
        cout << "X.X";
    }
    if(x == '1' || x == '7'){
        cout << "..X";
    }
    if(x == '2' || x == '3' || x == '4'|| x == '5' || x == '6' || x == '8' || x == '9'){
        cout << "XXX";
    }
}
void ifcout4(char x){
    if(x == '0' || x == '6' || x == '8'){
        cout << "X.X";
    }
    if(x == '1' || x == '7' || x == '9'){
        cout << "..X";
    }
    if(x == '2'){
        cout << "X..";
    }
    if(x == '3' || x == '4' || x == '5'){
        cout << "..X";
    }
}
void ifcout5(char x){
    if(x == '0' || x == '2' || x == '3' || x == '5' || x == '6' || x == '8' || x == '9'){
        cout << "XXX";
    }
    if(x == '1' || x == '4' || x == '7'){
        cout << "..X";
    }
}

int main(){
    int n;
    cin >> n;
    cin >> num;
    for(int i = 0;i < n - 1;i++){
        ifcout1(num[i]);
        cout << ".";
    }
    ifcout1(num[n - 1]);
    cout << endl;
    for(int i = 0;i < n - 1;i++){
        ifcout2(num[i]);
        cout << ".";
    }
    ifcout2(num[n - 1]);
    cout << endl;
    for(int i = 0;i < n - 1;i++){
        ifcout3(num[i]);
        cout << ".";
    }
    ifcout3(num[n - 1]);
    cout << endl;
    for(int i = 0;i < n - 1;i++){
        ifcout4(num[i]);
        cout << ".";
    }
    ifcout4(num[n - 1]);
    cout << endl;
    for(int i = 0;i < n - 1;i++){
        ifcout5(num[i]);
        cout << ".";
    }
    ifcout5(num[n - 1]);
    return 0;
}

by LYQ_666 @ 2024-08-03 17:42:51

#include<bits/stdc++.h>
using namespace std;
char a[1000001];
int main() 
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    } 
    for(int i=1;i<=n;i++)
    {
        if(i!=n)
        {
            if(a[i]=='0') cout<<"XXX.";
            if(a[i]=='1') cout<<"..X.";
            if(a[i]=='2') cout<<"XXX.";
            if(a[i]=='3') cout<<"XXX.";
            if(a[i]=='4') cout<<"X.X.";
            if(a[i]=='5') cout<<"XXX.";
            if(a[i]=='6') cout<<"XXX.";
            if(a[i]=='7') cout<<"XXX.";
            if(a[i]=='8') cout<<"XXX.";
            if(a[i]=='9') cout<<"XXX.";
        }
        else 
        {
            if(a[i]=='0') cout<<"XXX";
            if(a[i]=='1') cout<<"..X";
            if(a[i]=='2') cout<<"XXX";
            if(a[i]=='3') cout<<"XXX";
            if(a[i]=='4') cout<<"X.X";
            if(a[i]=='5') cout<<"XXX";
            if(a[i]=='6') cout<<"XXX";
            if(a[i]=='7') cout<<"XXX";
            if(a[i]=='8') cout<<"XXX";
            if(a[i]=='9') cout<<"XXX";
        }
    }
    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        if(i!=n)
        {
            if(a[i]=='0') cout<<"X.X.";
            if(a[i]=='1') cout<<"..X.";
            if(a[i]=='2') cout<<"..X.";
            if(a[i]=='3') cout<<"..X.";
            if(a[i]=='4') cout<<"X.X.";
            if(a[i]=='5') cout<<"X...";
            if(a[i]=='6') cout<<"X...";
            if(a[i]=='7') cout<<"..X.";
            if(a[i]=='8') cout<<"X.X.";
            if(a[i]=='9') cout<<"X.X.";
        }
        else 
        {
            if(a[i]=='0') cout<<"X.X";
            if(a[i]=='1') cout<<"..X";
            if(a[i]=='2') cout<<"..X";
            if(a[i]=='3') cout<<"..X";
            if(a[i]=='4') cout<<"X.X";
            if(a[i]=='5') cout<<"X..";
            if(a[i]=='6') cout<<"X..";
            if(a[i]=='7') cout<<"..X";
            if(a[i]=='8') cout<<"X.X";
            if(a[i]=='9') cout<<"X.X";
        }
    }
    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        if(i!=n)
        {
            if(a[i]=='0') cout<<"X.X.";
            if(a[i]=='1') cout<<"..X.";
            if(a[i]=='2') cout<<"XXX.";
            if(a[i]=='3') cout<<"XXX.";
            if(a[i]=='4') cout<<"XXX.";
            if(a[i]=='5') cout<<"XXX.";
            if(a[i]=='6') cout<<"XXX.";
            if(a[i]=='7') cout<<"..X.";
            if(a[i]=='8') cout<<"XXX.";
            if(a[i]=='9') cout<<"XXX.";
        }
        else 
        {
            if(a[i]=='0') cout<<"X.X";
            if(a[i]=='1') cout<<"..X";
            if(a[i]=='2') cout<<"XXX";
            if(a[i]=='3') cout<<"XXX";
            if(a[i]=='4') cout<<"XXX";
            if(a[i]=='5') cout<<"XXX";
            if(a[i]=='6') cout<<"XXX";
            if(a[i]=='7') cout<<"..X";
            if(a[i]=='8') cout<<"XXX";
            if(a[i]=='9') cout<<"XXX";
        }
    }
    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        if(i!=n)
        {
            if(a[i]=='0') cout<<"X.X.";
            if(a[i]=='1') cout<<"..X.";
            if(a[i]=='2') cout<<"X...";
            if(a[i]=='3') cout<<"..X.";
            if(a[i]=='4') cout<<"..X.";
            if(a[i]=='5') cout<<"..X.";
            if(a[i]=='6') cout<<"X.X.";
            if(a[i]=='7') cout<<"..X.";
            if(a[i]=='8') cout<<"X.X.";
            if(a[i]=='9') cout<<"..X.";
        }
        else 
        {
            if(a[i]=='0') cout<<"X.X";
            if(a[i]=='1') cout<<"..X";
            if(a[i]=='2') cout<<"X..";
            if(a[i]=='3') cout<<"..X";
            if(a[i]=='4') cout<<"..X";
            if(a[i]=='5') cout<<"..X";
            if(a[i]=='6') cout<<"X.X";
            if(a[i]=='7') cout<<"..X";
            if(a[i]=='8') cout<<"X.X";
            if(a[i]=='9') cout<<"..X";
        }
    }
    cout<<endl;
    for(int i=1;i<=n;i++)
    {
        if(i!=n)
        {
            if(a[i]=='0') cout<<"XXX.";
            if(a[i]=='1') cout<<"..X.";
            if(a[i]=='2') cout<<"XXX.";
            if(a[i]=='3') cout<<"XXX.";
            if(a[i]=='4') cout<<"..X.";
            if(a[i]=='5') cout<<"XXX.";
            if(a[i]=='6') cout<<"XXX.";
            if(a[i]=='7') cout<<"..X.";
            if(a[i]=='8') cout<<"XXX.";
            if(a[i]=='9') cout<<"XXX.";
        }
        else 
        {
            if(a[i]=='0') cout<<"XXX";
            if(a[i]=='1') cout<<"..X";
            if(a[i]=='2') cout<<"XXX";
            if(a[i]=='3') cout<<"XXX";
            if(a[i]=='4') cout<<"..X";
            if(a[i]=='5') cout<<"XXX";
            if(a[i]=='6') cout<<"XXX";
            if(a[i]=='7') cout<<"..X";
            if(a[i]=='8') cout<<"XXX";
            if(a[i]=='9') cout<<"XXX";
        }
    }
    return 0;
}

暴力+1


|