博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
奇奇怪怪的冒泡排序 TOJ 2014: Scramble Sort
阅读量:6437 次
发布时间:2019-06-23

本文共 4375 字,大约阅读时间需要 14 分钟。

粘贴两个特别简单的冒泡排序

2014: Scramble Sort

Description

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

Input

The input will contain multiple lists, one per line. Each element of the list will be separated by a comma followed a space, and the list will be terminated by a period. The input will be terminated by 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, 30, -20, z, 1000, 1, Y.
50, 7, kitten, puppy, 2, orangutan, 52, -100, bird, worm, 7, beetle.
.

Sample Output

 

0.

banana, OrAnGe, strawberry.
Banana, orange, StRaWbErRy.
0, 2, 4, 6, 8, 10.
x, -20, 1, Y, 30, 1000, z.
-100, 2, beetle, bird, 7, kitten, 7, 50, orangutan, puppy, 52, worm.

分数字和字母,手写个cmp就好了

#include 
#include
#include
char s[100][30];char t[30];int cmp(int i,int j){ 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(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;}int main(){while(~scanf("%s",t)){ memset(s,0,sizeof(s)); if(strcmp(t,".")==0) break; int i; for(i=0;;i++){ int l=strlen(t); for(int j=0;j

2034: 面积排序 分享至QQ空间

Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte
Total Submit: 1163            Accepted:433

Description

给定三角形、矩形、圆等二维几何图形,请根据面积从大到小进行排序。

Input

 

输入数据包括有多行,每行为一个几何图形(不超过100个几何图形)。各种几何图形的输入格式如下:

三角形(x1,y1,x2,y2,x3,y3分别为三角形顶点坐标):
triangle x1 y1 x2 y2 x3 y3

矩形(x1,y1,x2,y2为矩形某对角线的端点,矩形的边与坐标轴平行)

rectangle x1 y1 x2 y2

圆(x1,y1为圆心坐标,r为半径)

circle x1 y1 r

 

Output

对各个图形分别进行编号命名,三角形命名为triangle1、triangle2...,矩形命名为rectangle1、rectangle2...,圆命名为circle1、circle2...

然后按照面积从大到小进行排序,如果面积相同,则根据名字按照字典序排序。每行输出一个形状的名字以及面积,用空格分隔,面积保留3位小数。

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
没毛病,这个真的不算很难的,s=fabs((x1*y2+x2*y3+x3*y1-x1*y3-x2*y1-x3*y2)/2);有些人恐怕是三角形面积的精度不对吧
#include 
#include
#include
double rectangle() { double x1,y1,x2,y2,s; scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); s=fabs((x1-x2)*(y1-y2)); return s;}double circle() { double x1,y1,r,s; scanf("%lf%lf%lf",&x1,&y1,&r); s=3.1415926*r*r; return s;}double triangle() { double x1,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); return s;}int main() { int i,j,k,tmp3; double a[101],tmp1; int p,q,r,c[101]; char s[101][10],st[10]="triangle",str[10]="circle",tmp2[10]; 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
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

 

 

转载于:https://www.cnblogs.com/BobHuang/p/6869263.html

你可能感兴趣的文章
kubernetes学习笔记 (二):k8s初体验
查看>>
swift3 0 流控制
查看>>
Data-Mediator专题之属性回调
查看>>
每天一个Linux命令之ps-查看系统进程信息
查看>>
图解JavaScript原型链继承
查看>>
用VIPER构建iOS应用
查看>>
Java开源诊断工具 Arthas 发布v3.1.0
查看>>
什么是以太坊
查看>>
高效开发者是如何个性化VS Code插件与配置的?
查看>>
Java日志那些事
查看>>
117. Populating Next Right Pointers in Each Node II
查看>>
【笔记】重学前端-winter
查看>>
大数据构建模块:选择体系结构和开源框架
查看>>
62. Unique Paths
查看>>
告诉你微信域名被封的原因和防封方案
查看>>
七个你没用过的炫酷开发工具推荐
查看>>
深度解析利用ES6进行Promise封装总结
查看>>
css的content属性
查看>>
熬过了互联网“寒冬”,接下来的金三银四你该怎么面试进BAT?
查看>>
Java 开源库精选(持续更新)
查看>>