C language · Comparing strings

Source: Internet
Author: User

Algorithm training Compare string time limit: 1.0s memory limit: 512.0MBProgramming implements a dictionary comparison of two strings S1 and S2. (Ensure that each string is not prefixed by another, and that the length is less than 100). If S1 and S2 are equal, the output is 0, and if they are not equal, the difference between the ASCII code of the first different character is indicated: if S1&GT;S2, the difference is positive, and if s1<s2, the difference is negative. Sample input Java Basic Sample output 8
1#include <stdio.h>2#include <string.h>3 intMain () {4     Chars1[ -],s2[ -];5scanf"%s%s",&s1,&S2);6     intLen1 =strlen (S1);7     intLen2 =strlen (S2);8     if(Len1 = =len2) {9          for(intI=0; i<len1;i++){Ten             if(S1[i] = =S2[i]) { Oneprintf"0"); A                 return 0; -             } -         } the}Else if(len1<len2) { -          for(intI=0; i<len1;i++){ -             if(S1[i]! =S2[i]) { -printf"%d", s1[i]-s2[i]); +                 return 0; -             } +         } A}Else if(len1>len2) { at          for(intI=0; i<len2;i++){ -             if(S1[i]! =S2[i]) { -printf"%d", s1[i]-s2[i]); -                 return 0; -             } -         } in     } -}

C language · Comparing strings

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.