第二章 啊哈!算法

xiaoxiao2021-02-28  88

一、围绕三个问题展开

     

   问题一:二分查找  

   问题二:  翻手掌

  

   问题三: 三阶段

  

#include <stdio.h> #include <stdlib.h> #include <string.h> #define WORDMAX 100 int charcomp(char *x, char *y) { return *x - *y; } int main() { char word[WORDMAX], sig[WORDMAX]; while (scanf("%s", word) != EOF) { strcpy(sig, word); qsort(sig, strlen(sig), sizeof(char), charcomp); printf("%s %s\n", sig, word); } return 0; } #include <stdio.h> #include <stdlib.h> #include <string.h> #define WORDMAX 100 int main() { char word[WORDMAX], sig[WORDMAX], oldsig[WORDMAX]; int linenum = 0; strcpy(oldsig, ""); while (scanf("%s %s", sig, word) != EOF) { if (strcmp(oldsig, sig) != 0 && linenum > 0) printf("\n"); strcpy(oldsig, sig); linenum++; printf("%s ", word); } printf("\n"); return 0; }

转载请注明原文地址: https://www.6miu.com/read-70763.html

最新回复(0)