| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1104 人关注过本帖
标题:刚学C#,编了个小程序,谁帮我简化一下,我感觉我编的忒麻烦...
只看楼主 加入收藏
z745701540p
Rank: 2
等 级:论坛游民
帖 子:10
专家分:14
注 册:2012-2-23
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:10 
刚学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
w024680
Rank: 4
等 级:业余侠客
帖 子:53
专家分:259
注 册:2010-7-27
收藏
得分:10 
可以把switch语句提取出来,做成一个方法,

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();
            s = MyPublic(x1);
            s += MyPublic(x2);
            s += MyPublic(x3);
            s += MyPublic(x4);
            s += MyPublic(x5);
           
            while (Q == 0)
            {
                Console.WriteLine("请输入二号参赛选手的姓氏准备迎战");
                x11 = Console.ReadLine();
                x22 = Console.ReadLine();
                x33 = Console.ReadLine();
                x44 = Console.ReadLine();
                x55 = Console.ReadLine();

                s1 = MyPublic(x11);
                s1 += MyPublic(x22);
                s1 += MyPublic(x33);
                s1 += MyPublic(x44);
                s1 += MyPublic(x55);

                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("感谢使用,再见。");
                }
            }
            Console.ReadKey();
        }

        public static int MyPublic(string x1)
        {

            int s = 0;
            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;
            }
            return s;
        }

ら.花舞花落泪 | ら.花哭花瓣飞
2012-03-04 14:35
cxw89401326
Rank: 2
等 级:论坛游民
帖 子:14
专家分:17
注 册:2012-2-14
收藏
得分:0 
用for循环吧,这样会减少下代码量
2012-03-05 13:53
qq751673569
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-2-23
收藏
得分:0 
有这么多重复的代码,建议写个类class里,然后调用就OK啦
2012-03-05 14:18
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:10 
程序代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 姓名大冒险
{
    class Program
    {
        static void SetValue(string x,ref int s)
        {
            List<string> list = new List<string>() {
                "a#1", "b#1", "c#1", "d#1", "e#1",
                "f#1", "g#1", "h#1", "i#1", "j#1",
                "k#1", "l#1", "m#1", "n#1", "o#1",
                "p#1", "q#1", "r#1", "s#1", "t#1",
                "u#1", "v#1", "w#1", "x#1", "y#1",
                "z#1"};
            for (int i = 0; i < list.Count; i++)
            {
                if (x.Trim() == list[i].Split('#')[0].Trim())
                {
                    s = s + Int32.Parse(list[i].Split('#')[1].Trim());
                    break;
                }
            }
        }
        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();

            //从这儿开始优化吧 上边的LZ自己可以在优化一下 Class到不至于 不是特别复杂 多写几个方法就可以了

            SetValue(x1,ref s);
            SetValue(x2, ref s);
            SetValue(x3, ref s);
            SetValue(x4, ref s);
            SetValue(x5, ref s);
            //下边的参照上便这么写 也可以简化不少代码

            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("感谢使用,再见。");
                }
            }
        }
    }
}


[ 本帖最后由 wangnannan 于 2012-3-5 15:23 编辑 ]

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2012-03-05 14:50
sailorli123
Rank: 1
等 级:新手上路
帖 子:6
专家分:7
注 册:2012-2-20
收藏
得分:0 
用class来实现,学以致用啊
2012-03-05 15:18
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
蒙少
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-3-6
收藏
得分:0 
c#是一种面向对象的程序设计语言,其内涵是类和对象,具体的应该考虑定义类和使用类,你应该在这方面着重一下
2012-03-06 11:53
daihailong20
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-3-7
收藏
得分:0 
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,x2,x3,x4,x5;
            string x11,x22,x33,x44,x55;
            Console.WriteLine("请输入一号参赛选手的姓氏准备挑战");
            x1 = Console.ReadLine();
            x2 = Console.ReadLine();
            x3 = Console.ReadLine();
            x4 = Console.ReadLine();
            x5 = Console.ReadLine();
            s=GetValue(x1)+GetValue(x2)+GetValue(x3)+GetValue(x4)+GetValue(x5);
            while (Q == 0)
            {
                Console.WriteLine("请输入二号参赛选手的姓氏准备迎战");
                x11 = Console.ReadLine();
                x22 = Console.ReadLine();
                x33 = Console.ReadLine();
                x44 = Console.ReadLine();
                x55 = Console.ReadLine();
                s1=GetValue(x11)+GetValue(x22)+GetValue(x33)+GetValue(x44)+GetValue(x55);
                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("感谢使用,再见。");
                }
            }
        }
    public int GetValue(x)
    {
        int value = 0;
        for(int i=0;char a = 'a';a<='z';a++,i++)
        {
           if(x == a)
           {
              value=i;
              break;
           }
           else
           {
              value=13;
           }
        }
        return value;
    }
    }
}
以上代码未经测试,仅供参考。
2012-03-07 13:06
快速回复:刚学C#,编了个小程序,谁帮我简化一下,我感觉我编的忒麻烦...
数据加载中...
 
   



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

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