UVA10905 Children ' s Game

Source: Internet
Author: User

Problem Link: UVA10905 children ' s Game. basic level exercises, written in C + + language program.

Test Instructions Description: Enter n positive integers to connect them to one of the largest integers.

Problem analysis: There are three main points, one is not to put large integers in front, such as 12 and 3, the largest integer is 312, and the second is not able to simply use the function strcmp () to compare, for example 9 and 90, the largest integer is 990 instead of 909, three is n integers, Some may be large integers, wrote a C language program, always AC, and finally understand.

The AC C + + language program is as follows:

/* <span style= "Font-family:simsun;" >uva</span>10905 Children ' s Game */#include <iostream> #include <cstdio> #include <algorithm >using namespace std; #define MAXN 50string Val[maxn];bool cmp (string A, string b) {   return a+b > B+a;} int main () {    int n;    while (scanf ("%d", &n)!=eof && n! = 0)  {for      (int i=0; i<n; i++)         cin >> Val[i];      Sort (val, Val + N, CMP);      for (int i=0; i<n; i++)         cout << val[i];      cout << Endl;   }   return 0;}


The C language program without AC is as follows:

/* <span style= "Font-family:simsun;" >uva</span>10905 Children ' s Game */#include <stdio.h> #include <string.h> #include <stdlib.h >typedef unsigned long long ULL; #define MAXN 50int N;  ULL Val[maxn];char sa[20], sb[20], sab[40], sba[40];int cmp (const void * A, const void * b) {    sprintf (SA, "%llu", * (ULL *) a);    sprintf (SAB, "%llu", * (ULL *) a);    sprintf (SB, "%llu", * (ULL *) b);    sprintf (SBA, "%llu", * (ULL *) b);    strcat (SAB, SB);    strcat (SBA, SA);    Return strcmp (SBA, SAB);} int main (void) {    int i;    while (scanf ("%d", &n)! = EOF && n! = 0) {        for (i=0; i<n; i++)            scanf ("%llu", &val[i]);        Qsort (Val, N, sizeof (val[0]), CMP);        for (i=0; i<n; i++)            printf ("%llu", Val[i]);        printf ("\ n");    }    return 0;}



UVA10905 children ' s Game

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.