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;
            }
        }
    }
  • 相关阅读:
    nginx 怎么通过域名访问8080端口(指定端口)
    node.js 部署的 vue 项目怎么在局域网访问
    MySQL的疑难问题解决
    win10下装ubuntu双系统(免U盘)
    文件、块、对象存储
    OpenShift定义的安全上下文约束(SCCs)
    OpenShift资源类型
    yum命令详解
    OCP3.9的网络
    NTP时间服务器搭建部署
  • 原文地址:https://www.cnblogs.com/Wzqa/p/2812372.html
Copyright © 2011-2022 走看看