"Algorithm" C + + graphics processing

Source: Internet
Author: User

Overview
    • General graphics output can not be used to cycle the output, the early construction of good graphics.
    • Two different ways

      * * Direct output of analog method * *
      * * Two-dimensional array construction output * *

问题描述利用字母可以组成一些美丽的图形,下面给出了一个例子:ABCDEFGBABCDEFCBABCDEDCBABCDEDCBABC这是一个5行7列的图形,请找出这个图形的规律,并输出一个n行m列的图形。输入格式输入一行,包含两个整数n和m,分别表示你要输出的图形的行数的列数。输出格式输出n行,每个m个字符,为你的图形。样例输入5 7样例输出ABCDEFGBABCDEFCBABCDEDCBABCDEDCBABC
    • Title Address: http://lx.lanqiao.cn/problem.page?gpid=T7

    • Code

A direct output simulation method for solution
#include <iostream>#include <cstring>#include <string>#include <algorithm>#include <cmath>using namespace std;int main(){    string src="ABCDEFGHIJKLMNOPQRSTUVWXYZ";    int length=src.length();    int n,m,j=0;string sum;string temp;     cin>>n>>m;     int k=m;     for(int i=0;i<n;i++){            sum="";        for(j=0;j<k;j++){            sum+=src[j];        }        k--;        if(i!=0){            temp+=src[i];        }        reverse(temp.begin(),temp.end());        cout<<temp+sum<<endl;        reverse(temp.begin(),temp.end());    }}
Solution of 22-dimensional array Direct output
#include <iostream>  using namespace std;   //方法二  int main()   {      unsigned int n,m;      cin>>n>>m;      int array[n][m];      for(int i=0;i<m;i++)//给第一行赋值65,66,67... 转化为char型即为A,B,C...      {          array[0][i] = i + 65;      }      for(int i=1;i<n;i++)      {             for(int j=1;j<m;j++)//从第二行开始,每一行从第二位数开始的值都是上一行的右移一位后直接搬下来的           {              array[i][j] = array[i-1][j-1];          }          array[i][0] = array[i-1][0] + 1;//给每一行的第一位赋值       }      for(int i=0;i<n;i++)//输出       {          for(int j=0;j<m;j++)          {              cout<<(char)array[i][j];          }          cout<<endl;      }      return 0;  }   
Three methods for solving the problem the question is different from the conventional one.
    • According to the law you can see that a is the root coordinate began to move to both sides, the connection method is very ingenious

#include <iostream>#include <cstring>#include <string>#include <algorithm>#include <cmath>using namespace std;int main(){   int n,m;   ios::sync_with_stdio(false);   cin>>n>>m;   for(int i=1;i<=n;i++){        for(int j=1;j<=m;j++){            cout<<(char)(fabs(j-i)+'A');        }        cout<<endl;   }}
Summarize
    • The output graph is the most important control of the cycle capability, which also involves the knowledge points of the matrix (rotation, multiplication, departure, etc.).

"Algorithm" C + + graphics processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.