(C syntax) ballot count, 45 votes

Source: Internet
Author: User

(C syntax) ballot count, 45 votes

Note:

Author: Ls_Hacker _ Bai Yang (http://www.cnblogs.com/hlwyfeng)

Function Definition and call. Pay attention to the Declaration

Int max (int xx, int yy, int zz); int min (int xxx, int yyy, int zzz );

Note the symbol array, such as char a [10]. array a contains 10 elements, a [0] ~ A [9], but it cannot contain 10 characters, because the symbol array has a '\ 0' at the end, which is automatic.

Char a [1000];

For (I = 0; I <= n; I ++) is not a character array, it is I <n, but because the character array has '\ n ', therefore, I <= n is used. Pay attention to the details.

Note the differences between I ++ and ++.

I = I + 1; equivalent to ++ I

More in-depth understanding of if

Note: The method for comparing two numbers

M = yy> zz? Yy: zz; n = xx> m? Xx: m;

 

 

Content: three abc students, n voting (n is required), count the votes of the three abc students, and the characters other than the three abc letters are waivers, print the number of candidates and votes by the number of votes received (the same number of votes are output in alphabetical order of abc)

Input description:

 

The first line n represents a personal vote

The second line contains n characters (the letters are case-insensitive. For example, both a and A indicate that a is voted for, and the characters other than abc are waived)

 

Output description:

The first row of the three rows is a letter (only one abc, followed by the number of votes), in the ascending order

 

Input example:

6 abcA1b

 

Output example:

A 2 B 2 c 1

 

# Include <stdio. h> int main () {int max (int xx, int yy, int zz); int min (int xxx, int yyy, int zzz); char a [1, 1000]; int n, I, x = 0, y = 0, z = 0, t, h; scanf ("% d", & n); for (I = 0; I <= n; I ++) // control the array capacity {a [I] = getchar (); if (a [I] = 'A' | a [I] = 'A') // The ASCLL code is also available here, 'A' is 97 {+ + x;} if (a [I] = 'B' | a [I] = 'B') {++ y ;} if (a [I] = 'C' | a [I] = 'C') {++ z ;}} t = max (x, y, z); h = min (x, y, z); if (t! = H) // if the numbers of a, B, and c are the same {if (x = t) {printf ("a % d \ n", x );} if (y = t) {printf ("B % d \ n", y);} if (z = t) {printf ("c % d \ n ", z);} if (x> h & x <t) {printf ("a % d \ n", x );} if (y> h & y <t) {printf ("B % d \ n", y);} if (z> h & z <t) {printf ("c % d \ n", z);} if (x = h) {printf ("a % d \ n", x );} if (y = h) {printf ("B % d \ n", y);} if (z = h) {printf ("c % d \ n ", z) ;}} else printf ("a % d \ nb % d \ nc % d \ n", x); return 0;} int ma X (int xx, int yy, int zz) {int m, n; m = yy> zz? Yy: zz; n = xx> m? Xx: m; return (n);} int min (int xxx, int yyy, int zzz) {int m, n; m = yyy <zzz? Yyy: zzz; n = xxx <m? Xxx: m; return (n );}

 


A syntax error is displayed for counting votes in vb for beginners.

A = Val (InputBox ("Enter the ballot paper, 0 for waivers,-1" for termination, "input box "))
You use Chinese Punctuation for separators,


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.