EXE made in 2017.9.15.

Gene Examiner

第一次做小程序。。坚强性还不是很够。。有问题求大神指教orz
下面是代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<windows.h>
using namespace std;

int n1,n2,m,g;
int vis[1000005];
char s[505],c[505];
unsigned long long a[505][505],b[505][505];
unsigned long long t[505],d[505];
int hash(unsigned long long a){return a*37%1000007;}

int get(char x){
    if(x=='A')return 1;
    if(x=='C')return 2;
    if(x=='G')return 3;
    if(x=='T')return 4;
    else return 0;
}

int p;
bool check(int x)
{
    for(int i=x;i<=m;i++)
    {
        memset(vis,0,sizeof(vis));
        int sign=0;
        for(int j=1;j<=n1;j++)
            vis[hash(a[j][i]-a[j][i-x]*t[x])]=1;

        for(int j=1;j<=n2;j++)
        {
            if(vis[hash(b[j][i]-b[j][i-x]*t[x])])
                {sign=1;break;}
        }
        if(sign)continue;
        p = i-x+1;
        return true;
    }
    return false;
}

void find(int x)
{
    int i=p;

    memset(vis,0,sizeof(vis));
    int sign=0;
    for(int j=1;j<=n1;j++)
        vis[hash(a[j][i]-a[j][i-x]*t[x])]=1;

    //for(int j=1;j<=n2;j++)
    {
        if(vis[hash(d[i]-d[i-x]*t[x])]==0)
            {sign=1;}
    }           

    if(sign)cout << "This GENE doesn't have the marked ones." << endl << endl;
    else cout << "Wow this is it!" << endl << endl;
}

int printable(int x,int h)
{
    int i=x+h;
    {
        memset(vis,0,sizeof(vis));
        int sign=0;
        for(int j=1;j<=n1;j++)
            vis[hash(a[j][i]-a[j][i-h]*t[h])]=1;

        for(int j=1;j<=n2;j++)
        {
            if(vis[hash(b[j][i]-b[j][i-h]*t[h])])
                {sign=1;break;}
        }
        if(sign)return 0;
        return x+1;
    }

}

void mv()
{
    for(int i=1;i<=100;i++)
    {
        system("cls");      
        cout << endl << endl << endl << endl << "                        --- GENE EXAMINER BY ISSAC ---" << endl;
        if(i%3==1)cout << endl << endl << endl << "                           Loading now.     " << i << "%      /" << endl;
        if(i%3==2)cout << endl << endl << endl << "                           Loading now..    " << i << "%      -" << endl;
        if(i%3==0)cout << endl << endl << endl << "                           Loading now...   " << i << "%      |" << endl;
        cout << endl << endl << endl << endl << endl << endl;
        cout << endl << endl << endl << endl << endl << endl;
        cout << endl << "                                                         made by 20170111 ^      " << endl;
        Sleep(10);      
    }
    Sleep(1000);    
}

int main()
{
    //freopen("hh.in","r",stdin);
    mv();

    system("cls");

    char gg[1000];

    Sleep(500);
    cout << "Welcome using GENE EXAMINER Version 1.0 , here are the tips while you are using." << endl; Sleep(1000);
    cout << "Do you know the steps? Enter '1' if not , or enter '0'." << endl;  Sleep(1000);
    cout << "Now enter here :"; cin >> gg;  
    while(gg[0]!='0'&&gg[0]!='1'||strlen(gg)>1){
        memset(gg,3,sizeof(gg));
        cout << endl << "Oh! I'm sorry but you can only enter '0' or '1' !" << endl;    Sleep(1000);
        cout << "Now enter here again:";    cin >> gg;      
    }g = gg[0]-'0';

    if(g){
        cout << endl << "This is an early vision so it could only examine one marked gene at a time. :(" << endl;   Sleep(1000);
        cout << "First, enter the length of all the gene you will enter later." << endl;    Sleep(1000);
        cout << "Such as for gene < AGCT > , enter '4'." << endl;   Sleep(1000);
        cout << "By the way, this program can only hold up to 500 alphabets... and don't enter   number which is lower than 1..." << endl;  Sleep(1000);
        cout << "But for most warning: DON'T ENTER ALPHABETS !!!" << endl;  Sleep(1000);
        cout << "Now enter here:";      
    }cin >> m;
    while(m>500||m<=0){
        cout << endl << "Oh! I'm sorry but you can only enter a number between 1 and 500!" << endl; Sleep(1000);
        cout << "Now enter here again:";    cin >> m;       
    }

    t[0]=1;
    for(int i=1;i<=m;i++)   t[i]=t[i-1]*37; 

    if(g){
        cout << endl << "Second, enter the number of the gene which has got the 'marked gene'." << endl;    Sleep(1000);
        cout << "Such as for gene < AGCT > and < AGCA > , they both have marked gene < AGC > ,   enter '2'." << endl;   Sleep(1000);    
        cout << "Also for most warning: DON'T ENTER ALPHABETS !!!" << endl; Sleep(1000);
        cout << "Now enter here:";      
    }cin >> n1;
        while(n1>500||n1<=0){
        cout << endl << "Oh! I'm sorry but you can only enter a number between 1 and 500!" << endl; Sleep(1000);
        cout << "Now enter here again:";    cin >> n1;      
    }

    if(g){
        cout << endl << "Third, enter the gene which has got the 'marked gene'." << endl;Sleep(1000);
        cout << "Such as for gene < AGCT > and < AGCA > , enter 'AGCT' , then press ENTER , then  enter 'AGCA'." << endl;   Sleep(1000);    
        cout << "Now enter here:" << endl;      
    }for(int i=1;i<=n1;i++)
    {
        int ggg=1;
        while(ggg){
            ggg=0;
            scanf("%s",s+1);
            for(int j=1;j<=m;j++)
              if(get(s[j]))
                a[i][j]=(a[i][j-1]*37+get(s[j]));       
              else{
                ggg=1;
                cout << "Oh! I'm sorry but you can only enter 'A','T','C'or'G'!" << endl;
                cout << "Now enter here again:" << endl;            
                break;
              } 
        }

    }

    if(g){
        cout << endl << "Fourth, enter the number of the gene which hasn't got the 'marked gene'." << endl; Sleep(1000);
        cout << "Such as for gene < AGCT > and < AGCA > , they both have marked gene < AGC >." << endl;     Sleep(1000);
        cout << "But for gene < ATCT > and < ATCA > , they both don't have marked gene < AGC >." << endl;   Sleep(1000);
        cout << "So enter '2'." << endl;    Sleep(1000);
        cout << "Also for most warning: DON'T ENTER ALPHABETS !!!" << endl; Sleep(1000);
        cout << "Now enter here:";      
    }cin >> n2;
    while(n1>500||n1<=0){
        cout << endl << "Oh! I'm sorry but you can only enter a number between 1 and 500!" << endl; Sleep(1000);
        cout << "Now enter here again:";    cin >> n2;      
    }

    if(g){
        cout << endl << "Fifth, enter the gene which hasn't got the 'marked gene'." << endl;Sleep(1000);
        cout << "Such as for gene < AGCT > and < AGCA > , they both have marked gene < AGC >." << endl; Sleep(1000);
        cout << "But for gene < ATCT > and < ATCA > , they both don't have marked gene < AGC >." << endl;Sleep(1000);
        cout << "So enter 'ATCT' , then press ENTER , then enter 'ATCA'." << endl;      Sleep(1000);
        cout << "Now enter here:" << endl;      
    }for(int i=1;i<=n2;i++){
        int ggg=1;
        while(ggg){
            ggg=0;
            scanf("%s",c+1);
            for(int j=1;j<=m;j++)
              if(get(c[j]))
                b[i][j]=(b[i][j-1]*37+get(c[j]));       
              else{
                ggg=1;
                cout << "Oh! I'm sorry but you can only enter 'A','T','C'or'G'!" << endl;
                cout << "Now enter here again:";
                break;
              } 
        }
    }

    int l=0,r=m;
    while(l<r)
    {
        int mid=(l+r)>>1;
        if(check(mid))r=mid; 
        else l=mid+1;
    }

    for(int i=0;i<=m-l;i++)
    {
        int j = printable(i,l);
        if(j){
            int cnt=1;
            while(cnt!=j){cout<<" ";cnt++;}cnt=1;
            while(cnt<=l){cout<<"^";cnt++;}
            cout << "  " << l << endl;
        }
    }

    Sleep(1000);
    cout << endl << "Now the program has marked the 'Marked Gene' out." << endl;

    cout << "Now Enter the GENE you want to examine or simply enter 'Q' to quit:" << endl;  Sleep(1000);
    if(g){
        cout << "Such as you wanna examine gene < AGCA > , just simply enter 'AGCA'." << endl << endl;  Sleep(1000);
    }

    while(1)
    {
        int ggg=1;
        while(ggg){
            ggg=0;
            scanf("%s",c+1);
            if(c[0]=='Q')
            {
                cout << endl << "Thank you for using this program!  ;D" << endl;    Sleep(1000);
                cout << endl << "I'll do it better next time... maybe...  orz" << endl; Sleep(1000);    
                return 0;
            }
            for(int j=1;j<=m;j++)
                if(get(c[j]))
                   d[j]=(d[j-1]*37+get(c[j]));  
                else{
                    ggg=1;
                    cout << "Oh! I'm sorry but you can only enter 'A','T','C'or'G'!" << endl;
                    break;
                }   
        }       
        find(l);
        if(g)cout << "Enter the GENE you want to examine or simply enter 'Q':" << endl; Sleep(1000);
        memset(d,0,sizeof(d));
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值