Array-07. Find the largest single-digit number in a batch of integers,-07 batch

Source: Internet
Author: User

Array-07. Find the largest single-digit number in a batch of integers,-07 batch

1/* 2 * Main. c 3 * E7-array-07. calculate the four * Created on, which contains the largest number of integers: 5 x/6 7, August 22, 2014 # include <stdio. h> 8 9 int main (void) {10 11 int array [1000], temp [10] = {0}; 12 int max = 0; 13 int I, N; 14 15 scanf ("% d", & N); 16 getchar (); 17 for (I = 0; I <N; I ++) {18 scanf ("% d", & array [I]); 19} 20 21 for (I = 0; I <N; I ++) {22 while (array [I]) {23 temp [array [I] % 10] ++; 24 array [I]/= 10; 25} 26} 27 28 for (I = 0; I <10; I ++) {29 if (max <temp [I]) 30 max = temp [I]; 31} 32 33 printf ("% d:", max); 34 for (I = 0; I <10; I ++) {35 if (temp [I] = max) 36 printf ("% d", I); 37} 38 printf ("\ n"); 39 40 return 0; 41}

 

This question is based on the C ++ code of a netizen. After testing, it is found that the execution efficiency of C language is slightly higher.

This is my intuitive feeling. Sometimes I use different languages and Algorithms for comparison. The results show that C memory is always small and time is short. Of course, the memory and time consumption of Java must be more than 30 times!

 

 

Question link:

Http://pat.zju.edu.cn/contests/basic-programming/%E6%95%B0%E7%BB%84-07

Refer:

Http://www.cnblogs.com/gnodidux/p/3822761.html

(This code is concise and refined !)

 

.


How to obtain the number with the most occurrences in the array (implemented in C)

The code is written in the txt document. modify the code if any error occurs.

Int num = new int [] {1, 2, 3, 1 };
Int num2 = new int [num. length];

Int B = 0;

For (int I = 0; I <num. length; I ++)
{
Int a = 0;
For (int j = 0; j <num. length; j ++)
{
If (num [I] = num [j])
{
A ++;
}
}
Num2 [I] =;
}

For (int I = 0; I <num. length; I ++)
{
For (int j = 0; j <num. length; j ++)
{
If (num [I] <num [j])
{
C = num [j];
}
}
}

Messageboxs. show ("the largest in the array is" + c)

"The maximum number of occurrences and the number of occurrences in the array are integers, and the maximum number and number of occurrences are displayed in the 8-digit output"

Suppose in array:
Dim B (), c ()
N =-1
For I = lbound (a) to ubound ()
F = false
If n> = 0 then
For j = 0 to n
If a (I) = B (j) then c (I) = c (I) + 1: f = true: exit
Next
End if
If not f then
N = n + 1
Redim preserve B (n)
B (n) = a (I)
Redim preserve c (n)
C (n) = 1
End if
Next
For I = 0 to n
If max <c (I) then max = c (I): j = I
Next
Print "maximum number ="; B (j)
Print "appears ="; c (j)

Related Article

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.