日期:2014-05-18 浏览次数:21023 次
static void Main(string[] args) { int m = Convert.ToInt32(Console.ReadLine()); for (int i = 1; i <= m; i++) { for (int j = 1; j <= i; j++) { Console.Write(j); } for (int j = i-1; j >=1; j--) { Console.Write(j); } Console.Write('\n'); } Console.ReadLine(); }
------解决方案--------------------
namespace ConsoleApplication5 { class Node { public int Value; public Node Next, Prior; public Node(int value) { Value = value; } } class Link { private Node Head, Tail; private int Amount; public Link() { for (int i = 1; i <= 100; i++) { Add(new Node(i)); } Tail.Next = Head; Head.Prior = Tail; } private void Add(Node node) { if (Head == null) Head = Tail = node; else { node.Prior = Tail; Tail.Next = node; Tail = node; } Amount++; } public void DispNode() { Node node = Head; for(int i = 1;i<=Amount;i++) { Console.WriteLine(node.Value); node = node.Next; } } private void Delete(Node node) { if (Head == node) Head = node.Next; node.Prior.Next = node.Next; node.Next.Prior = node.Prior; Amount--; } public void Account(int n) { Node node = Head; int i = 1; while (Amount >= n) { if (i++ == n) { Delete(node); i = 1; } node = node.Next; } } } class Program { static void Main(string[] args) { Link link = new Link(); link.Account(5); link.DispNode(); Console.ReadKey(); } }