Advertisement
erfanul007

soundex index

Dec 9th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. freopen("input.txt","r",stdin);
  8. char str[50];
  9. int i,j,k;
  10. for(i=1;i<10;i++){
  11. cout<<" ";
  12. }
  13. cout<<"NAME";
  14. for(i=i+4;i<35;i++){
  15. cout<<" ";
  16. }
  17. cout<<"SOUNDEX CODE"<<endl;
  18. while(scanf("%s",str)!=EOF){
  19. int ln=strlen(str);
  20. for(i=1;i<10;i++)
  21. cout<<" ";
  22. printf("%s",str);
  23. for(i=i+ln;i<35;i++)
  24. cout<<" ";
  25. cout<<str[0];
  26. int a[30];
  27. for(j=0;j<25;j++)
  28. a[j]=0;
  29. k=0;
  30. for(j=1;j<ln;j++){
  31. if(str[j]=='A' || str[j]=='E' || str[j]=='I' || str[j]=='O' || str[j]=='U' || str[j]=='Y' || str[j]=='W' || str[j]=='H')
  32. continue;
  33. if(str[j]==str[j-1])
  34. continue;
  35. if(str[j]=='B' || str[j]=='P' || str[j]=='F' || str[j]=='V'){
  36. a[k]=1;
  37. k++;
  38. continue;
  39. }
  40. if(str[j]=='C' || str[j]=='S' || str[j]=='K' || str[j]=='G' || str[j]=='J' || str[j]=='Q' || str[j]=='X' || str[j]=='Z'){
  41. a[k]=2;
  42. k++;
  43. continue;
  44. }
  45. if(str[j]=='D' || str[j]=='T'){
  46. a[k]=3;
  47. k++;
  48. continue;
  49. }
  50. if(str[j]=='L'){
  51. a[k]=4;
  52. k++;
  53. continue;
  54. }
  55. if(str[j]=='M' || str[j]=='N'){
  56. a[k]=5;
  57. k++;
  58. continue;
  59. }
  60. if(str[j]=='R'){
  61. a[k]=6;
  62. k++;
  63. continue;
  64. }
  65. }
  66. cout<<a[0]<<a[1]<<a[2]<<endl;
  67. }
  68. for(i=1;i<20;i++){
  69. cout<<" ";
  70. }
  71. cout<<"END OF OUTPUT"<<endl;
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement