Finding in a two-bit array--Young's matrix

Source: Internet
Author: User

-------------------------------------------------------------------------------------------------

" Young Matrix": That is, the array elements are incremented from left to right, ascending from top to bottom. To find the number in the array, the first

First the array has to meet the characteristics of the "young Matrix". To make it easy to understand, we can think of a two-bit array as a matrix, assuming I

is a row, J is a column, and the array is str, so long as it satisfies (str[i][j]<str[i][j+1] && str[i][j]<str[i+1][j]),

Note that the loop only needs to loop I-1 times when judging.

-------------------------------------------------------------------------------------------------


C Language code:

# include <stdio.h># include <stdlib.h># define max 3       /* defines a matrix size of 3 rows and 3 columns */       /*** assigns values to the array to determine if the "young matrix" is satisfied * * The feature of re-entering data if not satisfied. */int init (Int arr[][max])                         {     int i  = 0, j = 0;          printf (" Please enter 9 integers to assign to the array: \ n ");     for  (i = 0; i < max; i+ +)      {          for  (j  = 0; j < max; j++)           { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d", &arr[ I][J]); &Nbsp;         }     }           for  (i = 0; i < max-1; i++)      {          for  (j =  0; j < max-1; j++)           {                if  (Arr[i][j]  >= arr[i][j + 1] | | &NBSP;ARR[I][J]&NBSP;&GT;=&NBSP;ARR[I+1][J])                 {                     printf ("The array you entered does not meet the requirements, please re-enter \ n");                     return 1;               }           }     }           printf ("Congratulations on your assignment success \ n");      return 0;} /*** determines whether the number of x exists in the array */int insert (CONST&NBSP;INT&NBSP;ARR[][MAX],&NBSP;CONST&NBSP;INT&NBSP;X) {      int i = 0, j = 0;           for  (i = 0; i < max; i++)       {          for  (j = 0; j <  max; j++)           {                if  (X == arr[i][j])                 {                     return 1;                }          }      }      return -1;} Int main () {     int str[max][max] = { 0 };      int num = 0, ret = 0;     int  sign = 1;      while  (sign)      {           sign = init (str);      }          printf ("\ n Please enter the number to find:");    &NBSP;&NBSP;SCANF ("%d", &num);   &nbsP;  ret = insert (Str, num);      if  (1 ==  ret)      {          printf (" Congratulations to you!!! %d in the array \ n ", num);     }     else      {          printf ("Find failed!!! %d is not in the array!!! \ n ", num);      }     system (" Pause ");      return 0;}

------------------------------------------------------------------------------------------------------

Little knowledge of dry goods:

According to the International standard IEEE (Electrical and Electronic Engineering Association) 754, any one binary floating-point number V can be expressed in the following form:

V = ( -1) ^s * M * 2^E (S is symbol, M is valid number, E is factorial)

(1) ( -1) ^s indicates the sign bit, when S=0,V is positive, when s=1,v is negative.
(2) m indicates a valid number, greater than or equal to 1, less than 2.
(3) 2^e means digits.

------------------------------------------------------------------------------------------------------

This article is from the "Nobody" blog, please be sure to keep this source http://814193594.blog.51cto.com/10729329/1709689

Finding in a two-bit array--Young's 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.