Wuhan University of Science and technology acm:1009:0 start-up algorithm 63--bow matrix

Source: Internet
Author: User

Problem Description

Bow-type matrix for output n*m

Input multiple sets of test data
Input 2 integers n and m (not greater than) output per group

The bow matrix of the output n*m requires that the upper-left element is 1, (each element occupies 2 positions, on the right)

Sample Input
4 3
Sample Output
1  2  3 6  5  4 7  8  912 11 10

My Code:
1#include <iostream>2#include <iomanip>3 using namespacestd;4 5 intMain ()6 {7     intm,n,i,p;8      while(cin>>m>>N)9     {Ten          for(i=1; i<=m;i++) One         { A                 if(i%2==1) -                 {     -                      for(p=1;p <=n;p++) the                         if(p!=N) -COUT&LT;&LT;SETW (2) <<p+n* (I-1) <<" "; -                         Else -COUT&LT;&LT;SETW (2) <<p+n* (I-1); +cout<<Endl; -                 } +                 Else A                 { at                      for(p=1;p <=n;p++) -                         if(p!=N) -COUT&LT;&LT;SETW (2) << (((I-1) *n) + (n+1-p)) <<" "; -                         Else -COUT&LT;&LT;SETW (2) << (((I-1) *n) + (n+1-p)); -cout<<Endl; in                 } -         } to     } +     return 0; -}

Other code:

1#include <stdio.h>2 intMain () {3     intM,n;4      while(SCANF ("%d%d", &n,&m)! =EOF)5     {6         intDir=1;7         intCount=0;8          for(intI=0; i<n;i++){9             if(dir) {Ten                  for(intj=0; j<m;j++){ One                      A                     if(j==m-1) -                     { -printf"%2d",++count); the                     } -                     Else -                     { -printf"%2d",++count); +                     } -                 } +                  A}Else{ atcount=count+m; -                  for(intj=0; j<m;j++){ -                      -                     if(j==m-1) -                     { -printf"%2d", count--); in                     } -                     Else to                     { +printf"%2d", count--); -                     } the                 } *count=count+m; $             }Panax Notoginsengdir=!dir; -printf"\ n"); the         } +          A     }     the}
1#include <iostream>2#include <iomanip>3 using namespacestd;4 5 intMain ()6 {7     intRow,col;8     intk=-1;9     int*a=NULL;Ten     inti,j; One      while(cin>>row>>Col) A     { -k=-0; -         if(row> -|| Col> -) the         { -             return 0; -         } -  +A=New int[row*Col]; -  +          for(i=0; i<row;++i) A         { at             if(i%2==0) -             { -                   for(j=0; j<col;++j) -                  { -a[i*col+j]=++K; -                  } in  -             } to             Else +             { -                    for(j=col-1; j>=0;--j) the                  { *a[i*col+j]=++K; $                  }Panax Notoginseng             } -  the         } +          for(i=0; i<row;++i) A         { the              for(j=0; j<col-1;++j) +             { -COUT&LT;&LT;SETW (2) <<a[i*col+j]<<" "; $             } $COUT&LT;&LT;SETW (2) <<a[i*col+j]<<Endl; -         } -  the  - Wuyi     } the     return 0; -}

Wuhan University of Science and technology acm:1009:0 start-up algorithm 63--bow matrix

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.