Advertisement
theiron97

Gen.CPP

Sep 18th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3.  
  4. using namespace std;
  5.  
  6. int kiemTraSoNu(int soNu);
  7. int kiemTraNu(char nu);
  8. char* xuatMach2(char mang[], int sophantu);
  9.  
  10. int main(){
  11. char *Nu;
  12. int sonu;
  13. char * Nu2;
  14.  
  15. cout << "1 doan mach 3' 5' cua ban co bao nhieu Nu ?";
  16. cin >> sonu;
  17. cout << endl;
  18. while(kiemTraSoNu(sonu)){
  19. cin >> sonu;
  20. cout << endl;
  21. }
  22. Nu = new char [sonu];
  23. Nu2 = new char [sonu];
  24.  
  25. char nu;
  26. for(int i=0;i<sonu ;i++){
  27. cout << "Nu " << i+1 << " la : ";
  28. nu = getche();
  29. cout << endl;
  30. while(!kiemTraNu(nu)){
  31. cout << "Nu " << i+1 << " la : ";
  32. nu = getche();
  33. cout << endl;
  34. }
  35. }
  36.  
  37. cout << "Mach 5' 3' la : " << endl;
  38. Nu2 = xuatMach2(Nu,sonu);
  39. for(int i=0;i<sonu ;i++){
  40. if((i+1)%3==0) cout << " ";
  41. cout << Nu2[i] ;
  42. }
  43. }
  44.  
  45. int kiemTraSoNu(int soNu){
  46. if(soNu <= 0){
  47. cout << "So nu phai > 0";
  48. return 1;
  49. }
  50. if(soNu % 3 != 0){
  51. cout << "So nu phai chia het cho 3";
  52. return 1;
  53. }
  54. return 0;
  55. }
  56.  
  57. int kiemTraNu(char nu){
  58. switch(nu){
  59. case 'A' : return 1; break;
  60. case 'T' : return 1; break;
  61. case 'G' : return 1; break;
  62. case 'X' : return 1; break;
  63. }
  64. return 0;
  65. }
  66.  
  67. char* xuatMach2(int mang[], int sophantu){
  68. char *Nu2 = new char[sophantu];
  69.  
  70. for(int i=0;i<sophantu ;i++){
  71. if(mang[i]=='A') Nu2[i] = 'T';
  72. if(mang[i]=='T') Nu2[i] = 'A';
  73. if(mang[i]=='G') Nu2[i] = 'X';
  74. if(mang[i]=='X') Nu2[i] = 'G';
  75. }
  76. return Nu2;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement