Mainでstudentの構造体を定義し,年齢が大きい順に並べ替えて学生情報を入力する.(構造体の使い方及び泡立ち順)
5451 ワード
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 = 0; 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 = 0; i <count; i++)
{
for (int j = i+1; 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}
",s.code,s.name,s.old);
}
Console.ReadLine();
}
}
}