在Main中定义student的结构体,进行年龄从大到小依次排序录入学生信息。(结构体的用法以及冒泡排序)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions; namespace c编程练习题
{ class Program
{
public struct student //结构体的用法。
{
public int code;
public string name;
public int old;
}
static void Main(string[] args)
{
Console.WriteLine("请输入学生的人数");
int count = int.Parse(Console.ReadLine());
ArrayList arr=new ArrayList();
for (int i = ; i < count; i++)
{ student s = new student();
Console.WriteLine("学号:");
s.code = int.Parse(Console.ReadLine());
Console.WriteLine("姓名:");
s.name = Console.ReadLine();
Console.WriteLine("年龄:");
s.old = int.Parse(Console.ReadLine());
arr.Add(s);
}
for (int i = ; i <count; i++)
{
for (int j = i+; j < count ; j++)
{
if (((student)arr[i]).old<((student)arr[j]).old)
{
student temp = (student)arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
Console.WriteLine("学号 姓名 年龄 从大到小依次排列");
foreach (student s in arr)
{
Console.Write("{0} {1} {2}\n",s.code,s.name,s.old);
}
Console.ReadLine(); }
}
}
在Main中定义student的结构体,进行年龄从大到小依次排序录入学生信息。(结构体的用法以及冒泡排序)的更多相关文章
- Java基础知识强化之IO流笔记51:IO流练习之 键盘录入学生信息按照总分排序写入文本文件中的案例
1. 键盘录入学生信息(姓名,语文成绩,数学成绩,英语成绩),按照总分排序写入文本文件中 分析: A:创建学生类 B:创建集合对象 TreeSet<Student> ...
- Java中通过Array.sort()对数组从大到小排序
package com.itheimajavase; import java.util.Arrays; import java.util.Comparator; public class Day01 ...
- 对ArrayList中的Person对象按照先年龄从大到小,相同年龄的再按照姓名(姓名是英文的)的字母顺序进行排序.
ListDemo2.java ----------------- package com.fs.test; import java.util.ArrayList; import java.util.C ...
- 第m大的身份证号码(局部排序代全局、结构体排序)
第m大的身份证号码(点击) 时间限制: 1 Sec 内存限制: 128 MB ...
- IO流的练习4 —— 键盘录入学生成绩信息,进行排序后存入文本中
需求: 键盘录入5个学生信息(姓名,语文成绩,数学成绩,英语成绩),按照总分从高到低存入文本文件 分析: A:创建学生类 B:创建集合对象 TreeSet<Student> C:键盘录入学 ...
- go语言从例子开始之Example18_1.结构体中定义方法
Go 支持在结构体类型中定义方法 . Example: package main import "fmt" type product struct{ name string num ...
- 编写Java应用程序。首先,定义描述学生的类——Student,包括学号(int)、 姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age) 用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类—— TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测 试Stud
package zuoye; public class student { int age; String name; int stuNO; void outPut() { System.out.pr ...
- 首先,定义描述学生的类——Student,包括学号(int)、 姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age) 用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类—— TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测 试Student类的功能。
package lianxi; public class Student { String Name; int XveHao,Age; Student(String Name,int XveHao,i ...
- 5.编写Java应用程序。首先,定义描述学生的类——Student,包括学号(int)、 姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age) 用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类—— TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测 试St
Student类: package com.bao; public class Student { int stuNo;String name,sex;int age,weight; Student( ...
随机推荐
- 【C#】【Thread】SynchronizationContext线程间同步
SynchronizationContext在通讯中充当传输者的角色,实现功能就是一个线程和另外一个线程的通讯. 需要注意的是,不是每个线程都附加SynchronizationContext这个对象, ...
- Linux Linux程序练习七
题目:实现两个程序mysignal.mycontrl,mycontrl给mysignal发送SIGINT信号,控制mysignal是否在屏幕打印“hello”字符串. //捕捉信号 #include ...
- javarebel热部署 (转)
Java web开发部署效率浅析 在进行java web程序开发过程中,经常遇到这种问题,修改一个java文件(*.java),需要重启web服务器(如tomcat,weblogic等),部署项目.而 ...
- VBA的一些使用心得
VBA的知识比较零散,因此开一贴记录一下使用VBA时的一些方法和心得.主要针对Excel,参考在这里 1. Collection Class 大部分情况下,Collection Class是比数组(A ...
- [CareerCup] 11.4 Sort the File 文件排序
11.4 Imagine you have a 20 GB file with one string per line. Explain how you would sort the file. 这道 ...
- LeetCode 笔记24 Palindrome Partitioning II (智商碾压)
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- [C#详解] (1) 自动属性、初始化器、扩展方法
文章来源:Slark.NET-博客园 http://www.cnblogs.com/slark/p/CSharp-focus-1.html 代码下载:点我下载 目录 前言 属性与自动属性 属性 自动属 ...
- PHP Yii1.1.13(一):命令行创建应用~shop
第一节 初始目录结构 (1)初识目录结构 在创建应用之前,我们来看一下Yii 1.x版本的目录结构:将yii-1.1.13安装文件解压到网站根目录下,打开framework目录,其目录如下图所示 (2 ...
- Mediator Pattern --中介者模式原理及实现(C++)
主要参考<大话设计模式>和<设计模式:可复用面向对象软件的基础>两本书.本文介绍中介者模式的实现. 中介者模式:What it is:Define an object that ...
- (旧)子数涵数·Flash——初识ActionScript
一.什么是AS(ActionScript) ActionScript,简称AS,中译为"动作脚本语言". 用于在Flash上实现一些光用Flash无法实现的功能. 在Flash界面 ...