标题:刚学C#,编了个小程序,谁帮我简化一下,我感觉我编的忒麻烦...
取消只看楼主
z745701540p
Rank: 2
等 级:论坛游民
帖 子:10
专家分:14
注 册:2012-2-23
结帖率:100%
已结贴  问题点数:20 回复次数:2 
刚学C#,编了个小程序,谁帮我简化一下,我感觉我编的忒麻烦...
程序大体意思就是输入两个人的姓,然后通过一个无聊的式子运算得出两个数,再把这两个数比大小,谁大谁赢。
我感觉我编的好像忒麻烦,全是重复的东西,但又不知道该如何简化...



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 姓名大冒险
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = 0, s1 = 0,Q=0;
            string x1;
            string x2;
            string x3;
            string x4;
            string x5;
            string x11;
            string x22;
            string x33;
            string x44;
            string x55;
            Console.WriteLine("请输入一号参赛选手的姓氏准备挑战");
            x1 = Console.ReadLine();
            x2 = Console.ReadLine();
            x3 = Console.ReadLine();
            x4 = Console.ReadLine();
            x5 = Console.ReadLine();
            switch (x1)
            {
                case "a": s = s + 1; break;
                case "b": s = s + 2; break;
                case "c": s = s + 3; break;
                case "d": s = s + 4; break;
                case "e": s = s + 5; break;
                case "f": s = s + 6; break;
                case "g": s = s + 7; break;
                case "h": s = s + 8; break;
                case "i": s = s + 9; break;
                case "j": s = s + 10; break;
                case "k": s = s + 11; break;
                case "l": s = s + 12; break;
                case "m": s = s + 13; break;
                case "n": s = s + 14; break;
                case "o": s = s + 15; break;
                case "p": s = s + 16; break;
                case "q": s = s + 17; break;
                case "r": s = s + 18; break;
                case "s": s = s + 19; break;
                case "t": s = s + 20; break;
                case "u": s = s + 21; break;
                case "v": s = s + 22; break;
                case "w": s = s + 23; break;
                case "x": s = s + 24; break;
                case "y": s = s + 25; break;
                case "z": s = s + 26; break;
                default: s = s + 13; break;
            }
            switch (x2)
            {
                case "a": s = s + 1; break;
                case "b": s = s + 2; break;
                case "c": s = s + 3; break;
                case "d": s = s + 4; break;
                case "e": s = s + 5; break;
                case "f": s = s + 6; break;
                case "g": s = s + 7; break;
                case "h": s = s + 8; break;
                case "i": s = s + 9; break;
                case "j": s = s + 10; break;
                case "k": s = s + 11; break;
                case "l": s = s + 12; break;
                case "m": s = s + 13; break;
                case "n": s = s + 14; break;
                case "o": s = s + 15; break;
                case "p": s = s + 16; break;
                case "q": s = s + 17; break;
                case "r": s = s + 18; break;
                case "s": s = s + 19; break;
                case "t": s = s + 20; break;
                case "u": s = s + 21; break;
                case "v": s = s + 22; break;
                case "w": s = s + 23; break;
                case "x": s = s + 24; break;
                case "y": s = s + 25; break;
                case "z": s = s + 26; break;
                default: s = s + 13; break;   
            }
            switch (x3)
            {
                case "a": s = s + 1; break;
                case "b": s = s + 2; break;
                case "c": s = s + 3; break;
                case "d": s = s + 4; break;
                case "e": s = s + 5; break;
                case "f": s = s + 6; break;
                case "g": s = s + 7; break;
                case "h": s = s + 8; break;
                case "i": s = s + 9; break;
                case "j": s = s + 10; break;
                case "k": s = s + 11; break;
                case "l": s = s + 12; break;
                case "m": s = s + 13; break;
                case "n": s = s + 14; break;
                case "o": s = s + 15; break;
                case "p": s = s + 16; break;
                case "q": s = s + 17; break;
                case "r": s = s + 18; break;
                case "s": s = s + 19; break;
                case "t": s = s + 20; break;
                case "u": s = s + 21; break;
                case "v": s = s + 22; break;
                case "w": s = s + 23; break;
                case "x": s = s + 24; break;
                case "y": s = s + 25; break;
                case "z": s = s + 26; break;
                default: s = s + 13; break;
            }
            switch (x4)
            {
                case "a": s = s + 1; break;
                case "b": s = s + 2; break;
                case "c": s = s + 3; break;
                case "d": s = s + 4; break;
                case "e": s = s + 5; break;
                case "f": s = s + 6; break;
                case "g": s = s + 7; break;
                case "h": s = s + 8; break;
                case "i": s = s + 9; break;
                case "j": s = s + 10; break;
                case "k": s = s + 11; break;
                case "l": s = s + 12; break;
                case "m": s = s + 13; break;
                case "n": s = s + 14; break;
                case "o": s = s + 15; break;
                case "p": s = s + 16; break;
                case "q": s = s + 17; break;
                case "r": s = s + 18; break;
                case "s": s = s + 19; break;
                case "t": s = s + 20; break;
                case "u": s = s + 21; break;
                case "v": s = s + 22; break;
                case "w": s = s + 23; break;
                case "x": s = s + 24; break;
                case "y": s = s + 25; break;
                case "z": s = s + 26; break;
                default: s = s + 13; break;
            }
            switch (x5)
            {
                case "a": s = s + 1; break;
                case "b": s = s + 2; break;
                case "c": s = s + 3; break;
                case "d": s = s + 4; break;
                case "e": s = s + 5; break;
                case "f": s = s + 6; break;
                case "g": s = s + 7; break;
                case "h": s = s + 8; break;
                case "i": s = s + 9; break;
                case "j": s = s + 10; break;
                case "k": s = s + 11; break;
                case "l": s = s + 12; break;
                case "m": s = s + 13; break;
                case "n": s = s + 14; break;
                case "o": s = s + 15; break;
                case "p": s = s + 16; break;
                case "q": s = s + 17; break;
                case "r": s = s + 18; break;
                case "s": s = s + 19; break;
                case "t": s = s + 20; break;
                case "u": s = s + 21; break;
                case "v": s = s + 22; break;
                case "w": s = s + 23; break;
                case "x": s = s + 24; break;
                case "y": s = s + 25; break;
                case "z": s = s + 26; break;
                default: s = s + 13; break;
            }
            while (Q == 0)
            {
                Console.WriteLine("请输入二号参赛选手的姓氏准备迎战");
                x11 = Console.ReadLine();
                x22 = Console.ReadLine();
                x33 = Console.ReadLine();
                x44 = Console.ReadLine();
                x55 = Console.ReadLine();
                switch (x11)
                {
                    case "a": s1 = s1 + 1; break;
                    case "b": s1 = s1 + 2; break;
                    case "c": s1 = s1 + 3; break;
                    case "d": s1 = s1 + 4; break;
                    case "e": s1 = s1 + 5; break;
                    case "f": s1 = s1 + 6; break;
                    case "g": s1 = s1 + 7; break;
                    case "h": s1 = s1 + 8; break;
                    case "i": s1 = s1 + 9; break;
                    case "j": s1 = s1 + 10; break;
                    case "k": s1 = s1 + 11; break;
                    case "l": s1 = s1 + 12; break;
                    case "m": s1 = s1 + 13; break;
                    case "n": s1 = s1 + 14; break;
                    case "o": s1 = s1 + 15; break;
                    case "p": s1 = s1 + 16; break;
                    case "q": s1 = s1 + 17; break;
                    case "r": s1 = s1 + 18; break;
                    case "s": s1 = s1 + 19; break;
                    case "t": s1 = s1 + 20; break;
                    case "u": s1 = s1 + 21; break;
                    case "v": s1 = s1 + 22; break;
                    case "w": s1 = s1 + 23; break;
                    case "x": s1 = s1 + 24; break;
                    case "y": s1 = s1 + 25; break;
                    case "z": s1 = s1 + 26; break;
                    default: s1 = s1 + 13; break;
                }
                switch (x22)
                {
                    case "a": s1 = s1 + 1; break;
                    case "b": s1 = s1 + 2; break;
                    case "c": s1 = s1 + 3; break;
                    case "d": s1 = s1 + 4; break;
                    case "e": s1 = s1 + 5; break;
                    case "f": s1 = s1 + 6; break;
                    case "g": s1 = s1 + 7; break;
                    case "h": s1 = s1 + 8; break;
                    case "i": s1 = s1 + 9; break;
                    case "j": s1 = s1 + 10; break;
                    case "k": s1 = s1 + 11; break;
                    case "l": s1 = s1 + 12; break;
                    case "m": s1 = s1 + 13; break;
                    case "n": s1 = s1 + 14; break;
                    case "o": s1 = s1 + 15; break;
                    case "p": s1 = s1 + 16; break;
                    case "q": s1 = s1 + 17; break;
                    case "r": s1 = s1 + 18; break;
                    case "s": s1 = s1 + 19; break;
                    case "t": s1 = s1 + 20; break;
                    case "u": s1 = s1 + 21; break;
                    case "v": s1 = s1 + 22; break;
                    case "w": s1 = s1 + 23; break;
                    case "x": s1 = s1 + 24; break;
                    case "y": s1 = s1 + 25; break;
                    case "z": s1 = s1 + 26; break;
                    default: s1 = s1 + 13; break;
                }
                switch (x33)
                {
                    case "a": s1 = s1 + 1; break;
                    case "b": s1 = s1 + 2; break;
                    case "c": s1 = s1 + 3; break;
                    case "d": s1 = s1 + 4; break;
                    case "e": s1 = s1 + 5; break;
                    case "f": s1 = s1 + 6; break;
                    case "g": s1 = s1 + 7; break;
                    case "h": s1 = s1 + 8; break;
                    case "i": s1 = s1 + 9; break;
                    case "j": s1 = s1 + 10; break;
                    case "k": s1 = s1 + 11; break;
                    case "l": s1 = s1 + 12; break;
                    case "m": s1 = s1 + 13; break;
                    case "n": s1 = s1 + 14; break;
                    case "o": s1 = s1 + 15; break;
                    case "p": s1 = s1 + 16; break;
                    case "q": s1 = s1 + 17; break;
                    case "r": s1 = s1 + 18; break;
                    case "s": s1 = s1 + 19; break;
                    case "t": s1 = s1 + 20; break;
                    case "u": s1 = s1 + 21; break;
                    case "v": s1 = s1 + 22; break;
                    case "w": s1 = s1 + 23; break;
                    case "x": s1 = s1 + 24; break;
                    case "y": s1 = s1 + 25; break;
                    case "z": s1 = s1 + 26; break;
                    default: s1 = s1 + 13; break;
                }
                switch (x44)
                {
                    case "a": s1 = s1 + 1; break;
                    case "b": s1 = s1 + 2; break;
                    case "c": s1 = s1 + 3; break;
                    case "d": s1 = s1 + 4; break;
                    case "e": s1 = s1 + 5; break;
                    case "f": s1 = s1 + 6; break;
                    case "g": s1 = s1 + 7; break;
                    case "h": s1 = s1 + 8; break;
                    case "i": s1 = s1 + 9; break;
                    case "j": s1 = s1 + 10; break;
                    case "k": s1 = s1 + 11; break;
                    case "l": s1 = s1 + 12; break;
                    case "m": s1 = s1 + 13; break;
                    case "n": s1 = s1 + 14; break;
                    case "o": s1 = s1 + 15; break;
                    case "p": s1 = s1 + 16; break;
                    case "q": s1 = s1 + 17; break;
                    case "r": s1 = s1 + 18; break;
                    case "s": s1 = s1 + 19; break;
                    case "t": s1 = s1 + 20; break;
                    case "u": s1 = s1 + 21; break;
                    case "v": s1 = s1 + 22; break;
                    case "w": s1 = s1 + 23; break;
                    case "x": s1 = s1 + 24; break;
                    case "y": s1 = s1 + 25; break;
                    case "z": s1 = s1 + 26; break;
                    default: s1 = s1 + 13; break;
                }
                switch (x55)
                {
                    case "a": s1 = s + 1; break;
                    case "b": s1 = s + 2; break;
                    case "c": s1 = s + 3; break;
                    case "d": s1 = s1 + 4; break;
                    case "e": s1 = s1 + 5; break;
                    case "f": s1 = s1 + 6; break;
                    case "g": s1 = s1 + 7; break;
                    case "h": s1 = s1 + 8; break;
                    case "i": s1 = s1 + 9; break;
                    case "j": s1 = s1 + 10; break;
                    case "k": s1 = s1 + 11; break;
                    case "l": s1 = s1 + 12; break;
                    case "m": s1 = s1 + 13; break;
                    case "n": s1 = s1 + 14; break;
                    case "o": s1 = s1 + 15; break;
                    case "p": s1 = s1 + 16; break;
                    case "q": s1 = s1 + 17; break;
                    case "r": s1 = s1 + 18; break;
                    case "s": s1 = s1 + 19; break;
                    case "t": s1 = s1 + 20; break;
                    case "u": s1 = s1 + 21; break;
                    case "v": s1 = s1 + 22; break;
                    case "w": s1 = s1 + 23; break;
                    case "x": s1 = s1 + 24; break;
                    case "y": s1 = s1 + 25; break;
                    case "z": s1 = s1 + 26; break;
                    default: s1 = s1 + 13; break;
                }
                s = ((s + 1000) / 23 + 17) % 13;
                s1 = ((s1 + 1000) / 23 + 17) % 13;
                if (s > s1)
                {
                    Console.WriteLine("恭喜{0}{1}{2}{3}{4}先生赢得此次姓氏PK的胜利", x1, x2, x3, x4, x5);
                }
                if (s1 > s)
                {
                    Console.WriteLine("恭喜{0}{1}{2}{3}{4}先生赢得此次姓氏PK的胜利", x11, x22, x33, x44, x55);
                }
                if (s == s1)
                {
                    Console.WriteLine("两位选手势均力敌");
                }
                Console.WriteLine("一号选手是否继续PK?继续请按“0”号键,否则请按任意数字键退出游戏");
                Q = int.Parse(Console.ReadLine());
                if (Q != 0)
                {
                    Console.WriteLine("感谢使用,再见。");
                }
            }
        }
    }
}
搜索更多相关主题的帖子: 如何 
2012-03-04 14:01
z745701540p
Rank: 2
等 级:论坛游民
帖 子:10
专家分:14
注 册:2012-2-23
得分:0 
回复 2楼 w024680
谢谢,我刚开始学,对C#有些地方运用起来还不是太熟练,我会把这个程序努力改进好的
收到的鲜花
  • w0246802012-03-06 12:40 送鲜花  1朵   附言:继续努力!在伟大的程序员,都是从无到有~
2012-03-05 22:16
z745701540p
Rank: 2
等 级:论坛游民
帖 子:10
专家分:14
注 册:2012-2-23
得分:0 
回复 5楼 wangnannan
谢谢~
2012-03-05 22:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-362189-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.061187 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved