zoukankan      html  css  js  c++  java
  • 编程实践63

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace CompareString
    {
        class Program
        {
            static void Main(string[] args)
            {
                string strX, strY;        //定义变量用来记录输入的字符串
                int x;
    
                //输入字符串的值
                Console.Write("请输入字符串1的值:");
                strX = Console.ReadLine();
                Console.Write("请输入字符串2的值:");
                strY = Console.ReadLine();
    
                //循环比较两个字符串相应位置上的字符
                x = bz(strX,strY);
                if (x == 2)
                {
                    Console.WriteLine("字符串{0}  小于  字符串{1}", strX, strY);
                }
    
                //字符串1与字符串2前面的字符全相同,且字符串1的长度大于字符串2的长度
                if (x == 1)
                {
                    Console.WriteLine("字符串{0}  大于  字符串{1}", strX, strY);
                }
    
                //字符串1与字符串2前面的字符全相同,且字符串1的长度等于字符串2的长度
                if (x == 0)
                {
                    Console.WriteLine("字符串{0}  等于  字符串{1}", strX, strY);
                }
                Console.ReadKey(true);
    
            }
            public static int bz(string strInput1, string strInput2)
            {
                int i;                 
    
                for (i = 0; i < strInput1.Length && i < strInput2.Length; i++)
                {
                    if (strInput1[i] > strInput2[i])
                    {
                      
                        return 1;
                    }
                    if (strInput1[i] < strInput2[i])
                    {
                       
                        return 2;
                    }
                }
    
                //字符串1与字符串2前面的字符全相同,且字符串1的长度小于字符串2的长度
                if (i == strInput1.Length && i < strInput2.Length)
                {
                    return 2;
                }
    
                //字符串1与字符串2前面的字符全相同,且字符串1的长度大于字符串2的长度
                if (i < strInput1.Length && i == strInput2.Length)
                {
                   
                    return 1;
                }
    
                //字符串1与字符串2前面的字符全相同,且字符串1的长度等于字符串2的长度
                if (i == strInput1.Length && i == strInput2.Length)
                {
                   
                    return 0;
                }
                return 0;
            }
        }
    }
  • 相关阅读:
    SPOJ 4487. Can you answer these queries VI splay
    Oracle Enterprise Linux 64-bit 下Oracle11g的监听配置改动及測试步骤
    欧拉函数
    安装Windows7步骤
    在Eclipse中执行、配置Hadoop
    java设计模式演示样例
    VC中获取窗体句柄的各种方法
    HTML5 Canvas中实现绘制一个像素宽的细线
    Java实现 蓝桥杯VIP 基础练习 Sine之舞
    Java实现 蓝桥杯VIP 基础练习 Sine之舞
  • 原文地址:https://www.cnblogs.com/Wzqa/p/2812372.html
Copyright © 2011-2022 走看看