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>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