Hangzhou Electric OJ 1004 realization and some traps of attention

Source: Internet
Author: User

The 1004 question is actually very simple, is wants you to count the most balloons the number, but in the output time but needs to be careful carefully, conforms to the question request.

In the output is the first note is the output order: If there are multiple numbers of the same color, first input first output, such as,

Red

Green

Red

Green

This situation requires an output

Red

Green

Post the AC code:

#include <stdio.h> #include <stdlib.h> #include <string.h>int main () {int n = 1;int i = 0;int max = 0;int Max  index = 0;int j = 0;char Color[1000][16];int *cnum;while (n) {scanf ("%d", &n), cnum = (int *) malloc (sizeof (int) * n); for (i = 0;i < N;i + +) {scanf ("%s", &color[i]);} for (i = n-1;i >= 0;i--) {Cnum[i] = 1;if (i! = n-1) {for (j = n-1;j > I;j--) if (strcmp (color[i],color[j]) = = 0) { Cnum[i] + +;}}} max = Cnum[0];maxindex = 0;for (i = 0;i < N;i + +) {if (Max < cnum[i]) {max = Cnum[i];maxindex = i;}} for (i = 0;i < N;i + +) if (max = = Cnum[i]) {printf ("%s\n", Color[i]);}} return 0;}

  

Hangzhou Electric OJ 1004 realization and some traps of attention

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.