Bizarre bubble sort TOJ 2014:scramble sort

Source: Internet
Author: User
Tags strcmp x2 y2

paste two very simple bubble sort 2014:scramble Sort

Description

In this problem you'll be given a series of lists containing both words and numbers. The goal is to sort these lists in such a the-all words be in alphabetical order and all numbers be in numerical or Der. Furthermore, if the nth element in the list was a number it must remain a number, and if it is a word it must remain a word .

Input

The input would contain multiple lists, one per line. Each element of the list is separated by a comma followed a space, and the list would be terminated by a period. The input would be terminated to a line containing only a single
Period.

Output

For each list in the input, output the scramble sorted list, separating each element of the list with a comma followed by A space, and ending the list with a period.

Sample Input

0.
Banana, strawberry, OrAnGe.
Banana, Strawberry, orange.
10, 8, 6, 4, 2, 0.
X, -20, z, +, 1, Y.
7, Kitten, puppy, 2, orangutan, -100, bird, worm, 7, Beetle.
.

Sample Output

0.
Banana, OrAnGe, strawberry.
Banana, Orange, strawberry.
0, 2, 4, 6, 8, 10.
X, -20, 1, Y, +, +, Z.
-100, 2, Beetle, Bird, 7, Kitten, 7, orangutan, puppy,, and worm.

Divide numbers and letters, and write a CMP.

#include <cstring>#include<cstdio>#include<ctype.h>Chars[ -][ -];Chart[ -];intcmpintIintj) {    if(s[i][0]=='-'&&s[j][0]=='-'){        if(Strlen (S[i]) <strlen (S[j]))return 1; Else if(Strlen (s[i]) = =strlen (S[j])) {            if(strcmp (S[i],s[j]) <0)                return 1; }    }    Else if(IsDigit (s[i][0]) &&isdigit (s[j][0])){        if(Strlen (s[i]) >strlen (S[j]))return 1; Else if(Strlen (s[i]) = =strlen (S[j])) {            if(strcmp (s[i],s[j]) >0)                return 1; }    }    Else if(s[j][0]=='-'&&isdigit (s[i][0]))        return 1; Else if(Isalpha (s[i][0]) &&isalpha (s[j][0]) &&stricmp (S[i],s[j]) >0)        return 1; return 0;}intMain () { while(~SCANF ("%s", T)) {memset (s),0,sizeof(s)); if(strcmp (T,".")==0) Break; inti;  for(i=0;; i++){        intL=strlen (t);  for(intj=0; j<l-1; j + +) S[i][j]=T[j]; if(t[l-1]=='.')         Break; Elsescanf"%s", T); }    intn=++i;  for(intI=0; i<n-1; i++)     for(intj=i+1; j<n;j++){            if(CMP (I,J)) {strcpy (t,s[j]);             strcpy (S[j],s[i]);            strcpy (s[i],t); }    }     for(intI=0; i<n;i++){        if(i) printf (", "); printf ("%s", S[i]); } printf (". \ n");}return 0;}
2034: Sort by area Time Limit (Common/java): 1000ms/10000ms Memory Limit:65536kbyte
Total submit:1163 accepted:433

Description

Given the two-dimensional geometry of triangles, rectangles, and circles, sort from large to small in terms of area.

Input

The input data includes multiple lines, one geometry per behavior (no more than 100 geometries). The input formats for the various geometries are as follows:
Triangles (X1,y1,x2,y2,x3,y3 are triangle vertex coordinates, respectively):
Triangle x1 y1 x2 y2 x3 y3

Rectangle (X1,y1,x2,y2 is the end of a diagonal of a rectangle, and the edge of the rectangle is parallel to the axis)
Rectangle x1 Y1 X2 y2

Circle (X1,y1 is the center coordinate, R is the radius)
Circle X1 Y1 R

Output

The individual figures are numbered, the triangles are named Triangle1, Triangle2 ..., the rectangles are named Rectangle1, Rectangle2 ..., the circle is named Circle1, Circle2 ...
Then sort by area from large to small, and if the area is the same, sort by name in dictionary order. Each row outputs a shape's name and area, separated by a space, and the area retains 3 decimal places.

Sample Input

Rectangle 0.0 0.0 1.0 2.0
Circle 0.0 0.0 1.0
Triangle 0.0 0.0 1.0 1.0 1.0 0.0
Rectangle 0.0 0.0 1.0 1.0
Circle 0.0 0.0 2.0

Sample Output

Circle2 12.566
Circle1 3.142
Rectangle1 2.000
Rectangle2 1.000
Triangle1 0.500

Hint

PI = 3.1415926 No problem, this is really not very difficult, s=fabs ((x1*y2+x2*y3+x3*y1-x1*y3-x2*y1-x3*y2)/2); Some people are afraid the accuracy of the triangle area is wrong.
#include <stdio.h>#include<math.h>#include<string.h>Doublerectangle () {Doublex1,y1,x2,y2,s; scanf ("%LF%LF%LF%LF",&x1,&y1,&x2,&y2); S=fabs ((x1-x2) * (y1-y2)); returns;}DoubleCircle () {Doublex1,y1,r,s; scanf ("%LF%LF%LF",&x1,&y1,&R); S=3.1415926*r*R; returns;}Doubletriangle () {Doublex1,y1,x2,y2,x3,y3,s; scanf ("%LF%LF%LF%LF%LF%LF",&x1,&y1,&x2,&y2,&x3,&y3); S=fabs ((x1*y2+x2*y3+x3*y1-x1*y3-x2*y1-x3*y2)/2); returns;}intMain () {intI,j,k,tmp3; Doublea[101],TMP1; intp,q,r,c[101]; Chars[101][Ten],st[Ten]="Triangle", str[Ten]="Circle", tmp2[Ten]; K=0; P=1; Q=1; R=1;  while(SCANF ("%s", s[k])! =EOF) {        if(strcmp (s[k],st) = =0) {A[k]=triangle (); C[K]=p++; } Else if(strcmp (s[k],str) = =0) {A[k]=Circle (); C[K]=q++; } Else{A[k]=rectangle (); C[K]=r++; } k++;    GetChar (); }     for(j=0; j<k-1; J + +)         for(i=0; i<k-j-1; i++) {            if(a[i]<a[i+1]) {TMP1=A[i]; A[i]=a[i+1]; A[i+1]=TMP1; Tmp3=C[i]; C[i]=c[i+1]; C[i+1]=Tmp3;                strcpy (Tmp2,s[i]); strcpy (S[i],s[i+1]); strcpy (S[i+1],TMP2); } Else if(a[i]==a[i+1]) {                if(strcmp (s[i],s[i+1]) >0) {strcpy (tmp2,s[i]); strcpy (S[i],s[i+1]); strcpy (S[i+1],TMP2); Tmp3=C[i]; C[i]=c[i+1]; C[i+1]=Tmp3; } Else if(strcmp (s[i],s[i+1])==0) {                    if(c[i]>c[i+1]) {Tmp3=C[i]; C[i]=c[i+1]; C[i+1]=Tmp3; }                }            }        }     for(i=0; i<k; i++) printf ("%s%d%.3f\n", S[i],c[i],a[i]); return 0;}

Bizarre bubble sort TOJ 2014:scramble sort

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.