两个顺序表A,B;比较他们公共前缀之后的第一个元素大小

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

void cmp(char *A,char *B)
{
    int i=0,j=0;
    while(i<strlen(A)||i<strlen(B))
    {
        if(A[i]==B[i]) i++;
        else break;
    }
    if(i==strlen(A)&&i==strlen(B)) printf("A=B");
    else if(i==strlen(A)||A[i]<B[i]) printf("A<B");
    else  printf("A>B");

}

int main()
{
    char A[30],B[30];
    scanf("%s %s",A,B);
    cmp(A,B);
    return 0;
}
 

猜你喜欢

转载自blog.csdn.net/qq_39350434/article/details/81254121