3 solutions

  • 1
    @ 2021-10-13 21:34:12

    1030 压力测试赛B题题解

    题目回顾

    Krik晚上失眠,躺着很无聊,于是突发奇想道阳台上去看星星。不失所望,那夜繁星当空、星河奔流。Kirk越看越精神,在繁星中发现了一个又一个的数字,刚学编程不久的Kirk想到,电脑上也有星星,何不操作一波呢! 经过一番痛苦的敲键盘事件之后,终于Kirk电脑屏幕上出现了下图十个数字的星星表达式: t

    (本来想给文本的,但是文本太丑了) 为了让大家体会一下Kirk痛苦的敲代码事件,所以Kirk给你两个整数A和B,你的任务是计算A+B的结果并且使用星星表达式输出

    题目分析

    从题中所给出的信息,我们可以得出:

    1. 两个数字相加会得到一个结果,并把结果转化为特殊表达形式输出。
    2. 特殊表达式如图所示,由于CMD的特性,只能一行输出完再输出下一行,所以我们要对每个数做一个拆解,把每一行特定输出。
    3. 特别要注意的是,测试样例中给出,两个数字之间有一个空格,第二个数字后无空格。

    可行代码

    这里给大家贴三份代码 (注:不建议直接CV过去解决问题,打表考的是细心,自己实操一下是最好的 /笔芯) Kirk的垃圾代码(强烈建议看看后面两篇比较好的写法,同时这也是几种不同思路,不说了Kirk思路最差)

    #include <stdio.h>
    
    void cout0(int line) {
        if (line == 1)
            printf("***");
        else if (line == 2)
            printf("* *");
        else if (line == 3)
            printf("* *");
        else if (line == 4)
            printf("* *");
        else if (line == 5)
            printf("***");
    }
    
    void cout1(int line) {
        if (line == 1)
            printf(" * ");
        else if (line == 2)
            printf(" * ");
        else if (line == 3)
            printf(" * ");
        else if (line == 4)
            printf(" * ");
        else if (line == 5)
            printf(" * ");
    }
    
    void cout2(int line) {
        if (line == 1)
            printf("***");
        else if (line == 2)
            printf("  *");
        else if (line == 3)
            printf("***");
        else if (line == 4)
            printf("*  ");
        else if (line == 5)
            printf("***");
    }
    
    void cout3(int line) {
        if (line == 1)
            printf("***");
        else if (line == 2)
            printf("  *");
        else if (line == 3)
            printf("***");
        else if (line == 4)
            printf("  *");
        else if (line == 5)
            printf("***");
    }
    
    void cout4(int line) {
        if (line == 1)
            printf("* *");
        else if (line == 2)
            printf("* *");
        else if (line == 3)
            printf("***");
        else if (line == 4)
            printf("  *");
        else if (line == 5)
            printf("  *");
    }
    
    void cout5(int line) {
        if (line == 1)
            printf("***");
        else if (line == 2)
            printf("*  ");
        else if (line == 3)
            printf("***");
        else if (line == 4)
            printf("  *");
        else if (line == 5)
            printf("***");
    }
    
    void cout6(int line) {
        if (line == 1)
            printf("***");
        else if (line == 2)
            printf("*  ");
        else if (line == 3)
            printf("***");
        else if (line == 4)
            printf("* *");
        else if (line == 5)
            printf("***");
    }
    
    void cout7(int line) {
        if (line == 1)
            printf("***");
        else if (line == 2)
            printf("  *");
        else if (line == 3)
            printf("  *");
        else if (line == 4)
            printf("  *");
        else if (line == 5)
            printf("  *");
    }
    
    void cout8(int line) {
        if (line == 1)
            printf("***");
        else if (line == 2)
            printf("* *");
        else if (line == 3)
            printf("***");
        else if (line == 4)
            printf("* *");
        else if (line == 5)
            printf("***");
    }
    
    void cout9(int line) {
        if (line == 1)
            printf("***");
        else if (line == 2)
            printf("* *");
        else if (line == 3)
            printf("***");
        else if (line == 4)
            printf("  *");
        else if (line == 5)
            printf("***");
    }
    
    int main() {
        int A, B;
        scanf("%d%d", &A, &B);
        int res = A + B; // 数据保证 10 <= A + B < 100
        int num1 = res / 10;
        int num2 = res % 10;
        for (int j = 1; j <= 6; j++) {
            if (num1 == 0)
                cout0(j);
            else if (num1 == 1)
                cout1(j);
            else if (num1 == 2)
                cout2(j);
            else if (num1 == 3)
                cout3(j);
            else if (num1 == 4)
                cout4(j);
            else if (num1 == 5)
                cout5(j);
            else if (num1 == 6)
                cout6(j);
            else if (num1 == 7)
                cout7(j);
            else if (num1 == 8)
                cout8(j);
            else if (num1 == 9)
                cout9(j);
            putchar(' ');
            if (num2 == 0)
                cout0(j);
            else if (num2 == 1)
                cout1(j);
            else if (num2 == 2)
                cout2(j);
            else if (num2 == 3)
                cout3(j);
            else if (num2 == 4)
                cout4(j);
            else if (num2 == 5)
                cout5(j);
            else if (num2 == 6)
                cout6(j);
            else if (num2 == 7)
                cout7(j);
            else if (num2 == 8)
                cout8(j);
            else if (num2 == 9)
                cout9(j);
            putchar('\n');
        }
        return 0;
    }
    

    大佬代码一(膜拜)

    #include<iostream>
    using namespace std;
    string x[15][10];
    int ans[105],cou;
    int main(){
    	ios::sync_with_stdio(false);
    	x[0][0]="***";
    	x[0][1]="* *";
    	x[0][2]="* *";
    	x[0][3]="* *";
    	x[0][4]="***";
    	
    	x[1][0]=" * ";
    	x[1][1]=" * ";
    	x[1][2]=" * ";
    	x[1][3]=" * ";
    	x[1][4]=" * ";
    	
    	x[2][0]="***";
    	x[2][1]="  *";
    	x[2][2]="***";
    	x[2][3]="*  ";
    	x[2][4]="***";
    	
    	x[3][0]="***";
    	x[3][1]="  *";
    	x[3][2]="***";
    	x[3][3]="  *";
    	x[3][4]="***";
    	
    	x[4][0]="* *";
    	x[4][1]="* *";
    	x[4][2]="***";
    	x[4][3]="  *";
    	x[4][4]="  *";
    	
    	x[5][0]="***";
    	x[5][1]="*  ";
    	x[5][2]="***";
    	x[5][3]="  *";
    	x[5][4]="***";
    	
    	x[6][0]="***";
    	x[6][1]="*  ";
    	x[6][2]="***";
    	x[6][3]="* *";
    	x[6][4]="***";
    	
    	x[7][0]="***";
    	x[7][1]="  *";
    	x[7][2]="  *";
    	x[7][3]="  *";
    	x[7][4]="  *";
    	
    	x[8][0]="***";
    	x[8][1]="* *";
    	x[8][2]="***";
    	x[8][3]="* *";
    	x[8][4]="***";
    	
    	x[9][0]="***";
    	x[9][1]="* *";
    	x[9][2]="***";
    	x[9][3]="  *";
    	x[9][4]="***";
    	
    	int a,b;
    	cin>>a>>b;
    	int xx=a+b,y=0,yy;
    	while(xx){
    		ans[cou++]=xx%10;
    		xx/=10;
    	}
    	for(int i=0;i<5;i++){
    		yy=y;
    		for(int j=cou-1;j>=0;j--){
    			cout<<x[ans[j]][i];
    			if(j)cout<<' ';
    		}
    		cout<<endl;
    	}
    	
    	
    	
    	return 0;
    }
    
    #include<iostream>
    using namespace std;
    char n0[6][6]={"***","* *","* *","* *","***"},n1[6][6]={" * "," * "," * "," * "," * "};
    char n2[6][6]={"***","  *","***","*  ","***"},n3[6][6]={"***","  *","***","  *","***"};
    char n4[6][6]={"* *","* *","***","  *","  *"},n5[6][6]={"***","*  ","***","  *","***"};
    char n6[6][6]={"***","*  ","***","* *","***"},n7[6][6]={"***","  *","  *","  *","  *"};
    char n8[6][6]={"***","* *","***","* *","***"},n9[6][6]={"***","* *","***","  *","***"};
    int main()
    {
    	int a,b;
    	cin>>a>>b;
    	int c=a+b;
    	char s[3];
    
    	s[1]=c/10;
    	s[2]=c%10;
    	int flag=0;
    			for(int p=0;p<5;p++)
    			{
    				for(int j=1;j<3;j++)
    				{
    					if(s[j]==1)cout<<n1[p];
    					if(s[j]==2)cout<<n2[p];
    					if(s[j]==3)cout<<n3[p];
    					if(s[j]==4)cout<<n4[p];
    					if(s[j]==5)cout<<n5[p];
    					if(s[j]==6)cout<<n6[p];
    					if(s[j]==7)cout<<n7[p];
    					if(s[j]==8)cout<<n8[p];
    					if(s[j]==9)cout<<n9[p];
    					if(s[j]==0)cout<<n0[p];
                        if(j==1)cout<<" ";
    				}
    				cout<<"\n";
    	}
    	return 0;
    }
    

    大佬代码二(继续膜拜)

    #include<iostream>
    using namespace std;
    char n0[6][6]={"***","* *","* *","* *","***"},n1[6][6]={" * "," * "," * "," * "," * "};
    char n2[6][6]={"***","  *","***","*  ","***"},n3[6][6]={"***","  *","***","  *","***"};
    char n4[6][6]={"* *","* *","***","  *","  *"},n5[6][6]={"***","*  ","***","  *","***"};
    char n6[6][6]={"***","*  ","***","* *","***"},n7[6][6]={"***","  *","  *","  *","  *"};
    char n8[6][6]={"***","* *","***","* *","***"},n9[6][6]={"***","* *","***","  *","***"};
    int main()
    {
    	int a,b;
    	cin>>a>>b;
    	int c=a+b;
    	char s[3];
    
    	s[1]=c/10;
    	s[2]=c%10;
    	int flag=0;
    			for(int p=0;p<5;p++)
    			{
    				for(int j=1;j<3;j++)
    				{
    					if(s[j]==1)cout<<n1[p];
    					if(s[j]==2)cout<<n2[p];
    					if(s[j]==3)cout<<n3[p];
    					if(s[j]==4)cout<<n4[p];
    					if(s[j]==5)cout<<n5[p];
    					if(s[j]==6)cout<<n6[p];
    					if(s[j]==7)cout<<n7[p];
    					if(s[j]==8)cout<<n8[p];
    					if(s[j]==9)cout<<n9[p];
    					if(s[j]==0)cout<<n0[p];
                        if(j==1)cout<<" ";
    				}
    				cout<<"\n";
    	}
    	return 0;
    }
    
    

    END 预祝学习愉快 /狗头

    • 0
      @ 2024-2-20 13:21:28

      打表并合理运用下标

      #include <bits/stdc++.h>
      using namespace std;
      
      #define DBG(x) cout << #x << "=" << x << endl
      
      char g[10][5][5] = {
        {  // 0
          "***",
          "* *",
          "* *",
          "* *",
          "***",
        },
        {  // 1
          " * ",
          " * ",
          " * ",
          " * ",
          " * ",
        },
        {  // 2
          "***",
          "  *",
          "***",
          "*  ",
          "***",
        },
        {  // 3
          "***",
          "  *",
          "***",
          "  *",
          "***",
        },
        {  // 4
          "* *",
          "* *",
          "***",
          "  *",
          "  *",
        },
        {  // 5
          "***",
          "*  ",
          "***",
          "  *",
          "***",
        },
        {  // 6
          "***",
          "*  ",
          "***",
          "* *",
          "***",
        },
        {  // 7
          "***",
          "  *",
          "  *",
          "  *",
          "  *",
        },
        {  // 8
          "***",
          "* *",
          "***",
          "* *",
          "***",
        },
        {  // 9
          "***",
          "* *",
          "***",
          "  *",
          "***",
        }
      };
      
      int nums[3] = {0, 0, 0};
      
      void solve() {
        int a, b;
      
        cin >> a >> b;
        int n = a + b;
        int t = 2;
        while (n) {
          nums[t--] = n % 10;
          n /= 10;
        }
      
        for (int r = 0; r < 5; r++) {
          for (int i = 0; i <= 2; i++) {
            if (i == 0 && nums[0] == 0) continue;
            if (i == 1 && nums[0] == 0 && nums[1] == 0) continue;
            int num = nums[i];
            cout << g[num][r] << (i == 2 ? "" : " ");
          }
          cout << endl;
        }
      }
      
      int main() {
        solve();
      
        return 0;
      }
      
      • 0
        @ 2022-4-10 17:24:17
        
        
        import java.util.Scanner;
        
        public class Main {
        
            public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                int end = sc.nextInt() + sc.nextInt();
                int n1, n2;
                n1 = end / 10;
                n2 = end % 10;
                String[][] stars = stars(n1, n2);
                printString(stars);
            }
        
            static String[][] copyT(String[][] a, String[][] b) {
                String[][] c = new String[5][7];
                for (int i = 0; i < 5; i++) {
                    for (int j = 0; j < 3; j++) {
                        c[i][j] = a[i][j];
                    }
                }
                for (int i = 0; i < 5; i++) {
                    c[i][3] = " ";
                }
                for (int i = 0; i < 5; i++) {
                    for (int j = 4; j < 7; j++) {
                        c[i][j] = b[i][j - 4];
                    }
                }
                return c;
            }
        
            static String[][] stars(int n1, int n2) {
                String[][] a = drawStars(n1);
                String[][] b = drawStars(n2);
                return copyT(a, b);
            }
        
            static String[][] drawStars(int n) {
                String[][] a = new String[5][3];
                reset(a);
                if (n == 0) {
                    s0(a);
                } else if (n == 1) {
                    s1(a);
                } else if (n == 2) {
                    s2(a);
                } else if (n == 3) {
                    s3(a);
                } else if (n == 4) {
                    s4(a);
                } else if (n == 5) {
                    s5(a);
                } else if (n == 6) {
                    s6(a);
                } else if (n == 7) {
                    s7(a);
                } else if (n == 8) {
                    s8(a);
                } else if (n == 9) {
                    s9(a);
                }
                return a;
            }
        
            static void reset(String[][] a) {
                for (int i = 0; i < 5; i++) {
                    for (int j = 0; j < 3; j++) {
                        a[i][j] = "*";
                    }
                }
            }
        
            static void s9(String[][] a) {
                s8(a);
                a[3][0] = " ";
            }
        
            static void s8(String[][] a) {
                s0(a);
                a[2][1] = "*";
            }
        
            static void s7(String[][] a) {
                for (int i = 1; i < 5; i++) {
                    a[i][0] = " ";
                    a[i][1] = " ";
                }
            }
        
            static void s6(String[][] a) {
                s5(a);
                a[3][0] = "*";
            }
        
            static void s5(String[][] a) {
                s3(a);
                a[1][0] = "*";
                a[1][2] = " ";
            }
        
            static void s4(String[][] a) {
                s9(a);
                a[0][1] = " ";
                a[4][1] = " ";
                a[4][0] = " ";
            }
        
            static void s3(String[][] a) {
                s2(a);
                a[3][2] = "*";
                a[3][0] = " ";
            }
        
            static void s2(String[][] a) {
                s0(a);
                a[2][1] = "*";
                a[1][0] = " ";
                a[3][2] = " ";
            }
        
            static void s1(String[][] a) {
                for (int i = 0; i < 5; i++) {
                    a[i][0] = " ";
                    a[i][2] = " ";
                }
            }
        
            static void s0(String[][] a) {
                a[1][1] = " ";
                a[2][1] = " ";
                a[3][1] = " ";
            }
        
            static void printString(String[][] a) {
                for (int i = 0; i < 5; i++) {
                    for (int j = 0; j < 7; j++) {
                        System.out.print(a[i][j]);
                    }
                    if (i != 4) {
                        System.out.println();
                    }
                }
            }
        }
        
        • 1

        Information

        ID
        29
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        4
        Tags
        # Submissions
        174
        Accepted
        87
        Uploaded By