zoukankan      html  css  js  c++  java
  • 比较字符串

    题目描述

    输入两个字符串,比较两字符串的长度大小关系。

    输入

    输入第一行表示测试用例的个数m,接下来m行每行两个字符串A和B,字符串长度不超过50。

    输出

    输出m行。若两字符串长度相等则输出A is equal long to B;若A比B长,则输出A is longer than B;否则输出A is shorter than B。

    样例输入 Copy

    2
    abc xy
    bbb ccc

    样例输出 Copy

    abc is longer than xy
    bbb is equal long to ccc
    #include<bits/stdc++.h>
    using namespace std;
    int f(char a[],char b[]){
        int ans=0;
        int temp=0;
        int a1=0,a2=1,a3=-1;
        for(int i=0;i<10;i++){
            if(a[i]>'0'){
                ans++;
            }
            if(b[i]>'0'){
                temp++;
            }
        }
        if(temp==ans){
            return a1;
        }else{
            if(temp>ans){
                return a2;
            }else{
                return a3;
            }
        }
    } 
    int main(){
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            int ans=0;
            char a[10]={0},b[10]={0};
            cin>>a>>b;
            if(f(a,b)==1){
                    cout<<a<<" is shorter than "<<b<<endl;
            }else{
                if(f(a,b)==0){
                    cout<<a<<" is equal long to "<<b<<endl;
                }else{
                    if(f(a,b)==-1){
                        cout<<a<<" is longer than "<<b<<endl;
                    }
                }
            }
        }
    }
    唐舞麟——武魂:蓝银皇、斗凯:金龙月语、身份:史莱克院长、唐门门主
  • 相关阅读:
    MyBatis简介
    JDBC报错:Cannot find class: com.mysql.jdbc.Driver
    进程,线程,协程
    mamp提示 more elements...
    获取html页面的参数
    php基础函数
    返回接口
    生成订单号
    xml转数组
    判断是否是微信浏览器
  • 原文地址:https://www.cnblogs.com/fangzm/p/13641838.html
Copyright © 2011-2022 走看看