Letter games and typing games

Source: Internet
Author: User

Letter games and typing games

[Problem description]

Peter liked playing the letter game, so he wrote an interesting game. The rules of the game are to fill in letters in a (N-1) * N table, rules: For each input N, starting from the upper left corner of the (N-1) * N letter area, enter A letter area counterclockwise from letter A. if the product is greater than 26, it will continue to be filled by A, B, and C in the new group. No border is required.

[Input]

Multiple groups of test data (less than 100 groups of data ). Only one row of test data in each group is an integer N (1 <= N <= 30), indicating the table width.

[Output]

For each group of input data, the output N-1 row is the filled table (N-1 rows, N integers per line, separated by spaces ).

[Example input]

5

[Sample output]

It represents a 4*5 clockwise letter area. Its style is as follows:

A B C D E

N O P Q F

M T S R G

L K J I H


Code:

# Include <stdio. h> # define MAX 100 char r [MAX] [MAX]; // r [] is used for filling in data // recursive call. The void solve (int x, int y, char ch, int m, int n)/* parameter description: x, y indicates the starting coordinate. ch indicates the current letter, m, n is the number of rows and columns to be filled in */{int I; // if m is 0, it indicates that the rectangle has been filled in if (m = 0) during the first recursion) {return;} // when m is set to 1, it indicates that one row and two columns are left unfilled, And if (m = 1) {for (I = 1; I <= n; I ++) {r [x] [y] = ch; y ++; ch ++; if (ch = 'Z' + 1) {ch = 'A' ;}}return;} // enter the row for (I = 1; I <n; I ++) {r [x] [y] = ch; y ++; ch ++; if (ch = 'Z' + 1) {ch = 'A ';}} // fill in the column for (I = 1; I <m; I ++) {r [x] [y] = ch; x ++; ch ++; if (ch = 'Z' + 1) {ch = 'A' ;}// enter the row for (I = 1; I <n; I ++) {r [x] [y] = ch; y --; ch ++; if (ch = 'Z' + 1) {ch = 'A ';}} // fill in the column for (I = 1; I <m; I ++) {r [x] [y] = ch; x --; ch ++; if (ch = 'Z' + 1) {ch = 'a';} // recursive call, fill in solve (x + 1, y + 1, ch, m-2, N-2);} int main () {int n; while (scanf ("% d", & n )! = EOF) {solve (, 'A', n-1, n); // print for (int I = 0; I <n-1; I ++) {for (int j = 0; j <n; j ++) {printf ("% c", r [I] [j]);} printf ("\ n") ;}} return 0 ;};

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.