Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4.  
  5. void soundex(const char s1[],char res[]){
  6. int i,k;
  7. int wordIdx=1;
  8.  
  9. int bool1=0;
  10. int bool2=0;
  11. int bool3=0;
  12. int bool4=0;
  13. int bool5=0;
  14. int bool6=0;
  15.  
  16.  
  17. char nr1[] ={'b','f','p','v'};
  18. char nr2[] = {'c','g','j','k','q','s','x','z'};
  19. char nr3[] = {'d','t'};
  20. char nr4 = 'l';
  21. char nr5[] = {'m','n'};
  22. char nr6 = 'r';
  23.  
  24. res[0]=toupper(s1[0]);
  25.  
  26. for(i=1;i<strlen(s1);i++){
  27. for(k=0;k<strlen(nr2);k++){
  28. if(bool1==0 && s1[i]==nr1[k] && wordIdx<6 && sizeof(nr1)/sizeof(char)>k){
  29. bool1=1;
  30. res[wordIdx]='1';
  31. wordIdx++;
  32. }
  33.  
  34. if(bool2==0 && s1[i]==nr2[k] && wordIdx<6 && sizeof(nr2)/sizeof(char)>k){
  35. bool2=1;
  36. res[wordIdx]='2';
  37. wordIdx++;
  38. }
  39.  
  40. if(bool3==0 && s1[i]==nr3[k] && wordIdx<6 && sizeof(nr3)/sizeof(char)>k ){
  41. bool3=1;
  42. res[wordIdx]='3';
  43. wordIdx++;
  44. }
  45. if(bool4==0 && s1[i]==nr4 && wordIdx<6 ){
  46. bool4=1;
  47. res[wordIdx]='4';
  48. wordIdx++;
  49. }
  50. if(bool5==0 && s1[i]==nr5[k] && wordIdx<6 && sizeof(nr5)/sizeof(char)>k){
  51. bool5=1;
  52. res[wordIdx]='5';
  53. wordIdx++;
  54. }
  55. if(bool6==0 && s1[i]==nr6 && wordIdx<6 ){
  56. bool6=1;
  57. res[wordIdx]='6';
  58. wordIdx++;
  59. }
  60.  
  61. }
  62.  
  63.  
  64. }
  65. if (wordIdx < 6){
  66. for(wordIdx=wordIdx;wordIdx<6;wordIdx++){
  67. res[wordIdx]='0';
  68. }
  69.  
  70. }
  71.  
  72. }
  73.  
  74. int main(void){
  75. char s1[100];
  76. char res[5];
  77. int i;
  78.  
  79. while(scanf("%s",s1)!=EOF){
  80. soundex(s1,res);
  81.  
  82. for(i=0;i<6;i++){
  83. printf("%c",res[i]);
  84. }
  85. printf("\n");
  86.  
  87.  
  88.  
  89. }
  90. return 0;
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement