Guest User

Untitled

a guest
Oct 21st, 2019
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* file: DNA[2].c */
  2. /* author: Tudor Grigorescu (email: t.grigorescu@student.rug.nl) */
  3. /* date: 17.10.2019 */
  4. /* version: 1.0 */
  5. /* Description: This program reads from the input two strings of characters which represent DNA strings which then it compares and sees if they match regardless of the letters positions */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. int main(int argc, char *argv[]){
  10. char *str1,*str2;
  11. int n,range=10000000,k;
  12. int hstr1[4],hstr2[4];
  13. for(int t=0;t<4;t++){
  14. hstr1[t]=0;
  15. hstr2[t]=0;
  16. }
  17. scanf("%d",&k);
  18. str1=(char *)malloc(range*sizeof(char));
  19. str2=(char *)malloc(range*sizeof(char));
  20. scanf("%s",str1);
  21. scanf("%s",str2);
  22. n=strlen(str1);
  23. //These for loop increments each letters histrogram ;
  24. for(int i=0;i<n;i++){
  25. switch(str1[i]){
  26. case 'A' : hstr1[0]+=1;
  27. break;
  28. case 'G' : hstr1[1]+=1;
  29. break;
  30. case 'T' : hstr1[2]+=1;
  31. break;
  32. case 'C' : hstr1[3]+=1;
  33. break;
  34. }
  35. }
  36. for(int j=0;j<n;j++){
  37. switch(str2[j]){
  38. case 'A' : hstr2[0]+=1;
  39. break;
  40. case 'G' : hstr2[1]+=1;
  41. break;
  42. case 'T' : hstr2[2]+=1;
  43. break;
  44. case 'C' : hstr2[3]+=1;
  45. break;
  46. }
  47. }
  48.  
  49. //In this for loop we check if the letters histrograms are different , if they are then we decrement the number of interchangable letters.
  50. for(int z=0;z<4;z++){
  51. if(hstr1[z]!=hstr2[z])
  52. k--;
  53. }
  54. //This if statement checks if the numbers of interchangable letters isnt an negative integer and thus checks if the strings are matching or not.
  55. if(k>=0){
  56. printf("YES\n");
  57. }else
  58. {
  59. printf("NO\n");
  60. }
  61. return 0;
  62. }
RAW Paste Data