Java面向对象6 (AA - AE)
2024-08-27 10:24:42
整理音乐(SDUT 2053)
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
int n=reader.nextInt();
String string[] =new String[10001];
int A[]=new int [10001];
int flag=0;
for(int i=1;i<=n;i++)
{
int m=reader.nextInt();
for(int j=1;j<=m;j++)
{
string[flag]=reader.next();
A[flag]=reader.nextInt();
flag++;
}
}
for(int i=0;i<flag-1;i++)
{
for(int j=0;j<flag-1-i;j++)
{
if(A[j]<A[j+1]||(A[j]==A[j+1]&&string[j].compareTo(string[j+1])>0))
{
int t=A[j];
A[j]=A[j+1];
A[j+1]=t;
String t1;
t1=string[j];
string[j]=string[j+1];
string[j+1]=t1;
}
}
}
for(int i=0;i<flag;i++)
{
if(i!=flag-1)
System.out.print(string[i]+" ");
else
{
System.out.println(string[i]);
}
}
reader.close();
}
}
AD 来淄博旅游(SDUT 2055)
import java.util.Scanner;
class List
{
String from[][] = new String[105][2105];
String to[][] = new String[105][2105];
int len1 = 0, len2 = 0;
int lens1[] = new int[105];
int lens2[] = new int[105];
List(int x)
{
to[0][0] = "zichuan";
to[1][0] = "linzi";
to[2][0] = "zhoucun";
to[3][0] = "boshan";
len2 = 4;
lens2[0] = lens2[1] = lens2[2] = lens2[3] = 1;
}
int fin(String a[][], int len, String x)
{
int i;
for(i = 0; i < len; i++)
{
if(a[i][0].equals(x) == true)break;
}
if(i < len)return i;
else return -1;
}
void SetData(String nam, String fro, String ti)
{
int p;
p = fin(from, len1, fro);
if(p == -1)
{
from[len1][0] = fro;
from[len1][1] = nam;
lens1[len1] = 2;
len1++;
}
else
{
from[p][lens1[p]] = nam;
lens1[p]++;
}
p = fin(to, len2, ti);
if(p != -1)
{
to[p][lens2[p]] = nam;
lens2[p]++;
}
}
void Print()
{
int i, j;
for(i = 0; i < len1; i++)
{
System.out.print(from[i][0] + " :");
for(j = 1; j < lens1[i]; j++)
{
System.out.print(" " + from[i][j]);
}
System.out.println();
}
for(i = 0; i < len2; i++)
{
System.out.print(to[i][0] + " :");
for(j = 1; j < lens2[i]; j++)
{
System.out.print(" " + to[i][j]);
}
System.out.println();
}
}
}
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n, i, j, k;
String nam, fro, to;
List li = new List(1);
n = cin.nextInt();
nam = cin.nextLine();
for(i = 0; i < n; i++)
{
nam = cin.next();
fro = cin.next();
to = cin.next();
li.SetData(nam, fro, to);
}
li.Print();
cin.close();
}
}
最新文章
- hibernate(九)多对多关联
- Socket Programming in C#--Introduction
- linq 多条件查询 where 拼接+分页
- 如何让多个不同版本的jquery库共存
- 使用bootstrap建立响应式网页——通栏轮播图(carousel)
- 【LeetCode】118. Pascal&#39;s Triangle
- MYSQL数据库45道练习题
- AB PLC首次IP地址如何分配
- 菜鸡学C语言之寻根溯源
- 苹果笔记本安装windows正版操作系统
- okhttp 解析respone:
- linux光标操作
- command not found解决方案
- SDN期末作业验收
- MVC4是不是类似于html页+ashx页之间用JSON通过AJAX交换数据这种方式、?
- How to return NULL string
- jquery源码学习-初始(1)
- Emmet常用语法
- tomcat6的编译和导入myeclipse
- P2258 子矩阵