Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* file: DNA[2].c */
- /* author: Tudor Grigorescu (email: t.grigorescu@student.rug.nl) */
- /* date: 17.10.2019 */
- /* version: 1.0 */
- /* 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 */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char *argv[]){
- char *str1,*str2;
- int n,range=10000000,k;
- int hstr1[4],hstr2[4];
- for(int t=0;t<4;t++){
- hstr1[t]=0;
- hstr2[t]=0;
- }
- scanf("%d",&k);
- str1=(char *)malloc(range*sizeof(char));
- str2=(char *)malloc(range*sizeof(char));
- scanf("%s",str1);
- scanf("%s",str2);
- n=strlen(str1);
- //These for loop increments each letters histrogram ;
- for(int i=0;i<n;i++){
- switch(str1[i]){
- case 'A' : hstr1[0]+=1;
- break;
- case 'G' : hstr1[1]+=1;
- break;
- case 'T' : hstr1[2]+=1;
- break;
- case 'C' : hstr1[3]+=1;
- break;
- }
- }
- for(int j=0;j<n;j++){
- switch(str2[j]){
- case 'A' : hstr2[0]+=1;
- break;
- case 'G' : hstr2[1]+=1;
- break;
- case 'T' : hstr2[2]+=1;
- break;
- case 'C' : hstr2[3]+=1;
- break;
- }
- }
- //In this for loop we check if the letters histrograms are different , if they are then we decrement the number of interchangable letters.
- for(int z=0;z<4;z++){
- if(hstr1[z]!=hstr2[z])
- k--;
- }
- //This if statement checks if the numbers of interchangable letters isnt an negative integer and thus checks if the strings are matching or not.
- if(k>=0){
- printf("YES\n");
- }else
- {
- printf("NO\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement