Ma Trận Xoắn ốc - Coder Dưa Hấu

Skip to content
Search for: Search Date: October 24, 2016Author: coderduahau 0 Comments #include<stdio.h> #define MAX 100 // ma tran xoan oc /* 1 2 3 8 9 4 7 6 5 */ FILE *fin = fopen("MATRANXOANOC.INP", "r"); FILE *fout = fopen("MATRANXOANOC.OUT", "w"); /* MATRANXOANOC.INP 3 5 */ int a[MAX][MAX], m, n; void inMaTran(){ for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++) fprintf(fout, "%10d", a[i][j]); fprintf(fout,"\n"); } } /* Khoi tao ma tran xoan oc a, co m hang, n cot */ void taoMaTranXoanOc(){ int d = 0, i, gt = 1; int hang = m - 1, cot = n - 1; while(gt <= m*n){ for(i = d; i <= cot; i++) { a[d][i] = gt++; // gan tu trai sang phai } for(i = d+1; i <= hang; i++){ a[i][cot] = gt++; // gan tu tren xuong duoi } for(i = cot-1; i>=d && gt <= m * n; i--){ a[hang][i]=gt++; // tu phai sang trai } for(i = hang-1; i>d && gt <= m * n; i--){ a[i][d] = gt++; // tu duoi len } d++; hang--; cot--; // thu nho xoan oc } inMaTran(); } main(){ fscanf(fin, "%d %d", &n, &m); printf("Kich thuoc cua ma tran la: %d x %d", n, m); printf("\n"); taoMaTranXoanOc(); fclose(fin); fclose(fout); }

Share this:

  • Tweet
Like Loading...

Related

Post navigation

Previous post: Tìm kiếm trên đồ thị Next post: How to learn computer vision

Leave a comment Cancel reply

Δ

Search for: Search

Archives

  • November 2017 (2)
  • August 2017 (1)
  • June 2017 (1)
  • May 2017 (1)
  • October 2016 (4)

Categories

  • Android (2)
  • C/C++ (4)
    • CTDL-GT (1)
    • Cơ bản (2)
    • Đồ thị (1)
  • Computer Vision (1)
  • HỌC MÁY (1)
  • Uncategorized (3)

Tags

Android appbar bfs dfs HỌC MÁY machine learning ma trận reusecode toolbar tìm kiếm Đồ thị Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use. To find out more, including how to control cookies, see here: Cookie Policy
  • Comment
  • Reblog
  • Subscribe Subscribed
    • Coder Dưa Hấu
    • Sign me up
    • Already have a WordPress.com account? Log in now.
    • Coder Dưa Hấu
    • Customize
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Copy shortlink
    • Report this content
    • View post in Reader
    • Manage subscriptions
    • Collapse this bar
%d Design a site like this with WordPress.comGet started

Từ khóa » Thuật Toán Ma Trận Xoắn ốc