Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- struct node{
- string sub;
- int num;
- node(string n):sub(n),num(1){};
- node(){};
- };
- int main()
- {
- string dna;
- int n;
- cin>>dna>>n;
- vector<node> ans;
- for(int i=0;i<dna.length()-n+1;i++)
- {
- string sub_temp=dna.substr(i,n);
- for(int j=0;j<ans.size();j++)
- {
- if(sub_temp==ans[j].sub)
- {
- ans[j].num++;
- goto subend;
- }
- }
- {
- node node_temp(sub_temp);
- ans.push_back(node_temp);
- }
- subend:
- ;
- }
- for(int i=0;i<ans.size();i++)
- {
- printf("> %s : %d\n",ans[i].sub.c_str(),ans[i].num);
- }
- }
- //ATCAGAGTCAGCAG
- //輸入說明:
- // 每筆輸入有一串DNA字串以及正整數n
- //
- //輸出說明:
- // 依照輸入的DNA字串和正整數n列出n個連續鹽基的重複次數
- //SAMPLE INPUT
- // ATCAGAGTCAGCAG 3
- //SAMPLE OUTPUT
- // > ATC : 1
- // > TCA : 2
- // > CAG : 3
- // > AGA : 1
- // > GAG : 1
- // > AGT : 1
- // > GTC : 1
- // > AGC : 1
- // > GCA : 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement