• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Welcome to Leon's Blog  
            日歷
            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011
            統(tǒng)計(jì)
            • 隨筆 - 30
            • 文章 - 0
            • 評(píng)論 - 51
            • 引用 - 0

            導(dǎo)航

            常用鏈接

            留言簿(4)

            隨筆分類

            隨筆檔案

            ACM

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

             
                 昨天晚上寫完了這道題,早上過來提交。 主要用到了插入排序算法,并且參看了桶排序算法,如果大家有什么好的想法,希望能夠共享一下,嘿嘿!我的代碼有哪里寫的不好,也請(qǐng)大家指教!
             1#include <stdlib.h>
             2#include <stdio.h>
             3typedef struct dNANumber
             4{
             5    char ch[100];
             6    int count;
             7}
            DNANumber;
             8
             9void Sort(DNANumber *arr, int rows)
            10{
            11    int i, j;
            12    DNANumber temp;
            13    for(i = 1; i < rows; i++)
            14    {
            15        temp = arr[i];
            16        for(j = i-1; j >= 0; j--)
            17        {
            18            if(arr[j].count > temp.count)
            19                arr[j+1= arr[j];
            20            else 
            21                break;
            22        }

            23        arr[j+1= temp;
            24    }

            25    return;
            26}

            27
            28int Index(char ch)
            29{
            30    switch(ch)
            31    {
            32    case 'A':
            33        return 0;
            34    case 'C':
            35        return 1;
            36    case 'G':
            37        return 2;
            38    case 'T':
            39        return 3;
            40    }

            41}

            42
            43void CountNumber(DNANumber *dna, int length)
            44{
            45    int count = 0;
            46    int letter[4= {0,0,0,0};
            47    int i, j;
            48    int temp;
            49    
            50    for(i = 0; i < length; i++)
            51    {
            52        letter[Index(dna->ch[i])]++;
            53    }

            54
            55    for(i = length-1; i >= 0; i--)
            56    {
            57        temp = Index(dna->ch[i]);
            58        for(j = temp+1; j < 4; j++)
            59        {
            60            count += letter[j];
            61        }

            62        letter[temp]--;            
            63    }

            64    dna->count = count;
            65    return;
            66}

            67int main(int argc, char* argv[])
            68{
            69    int length = 0, rows = 0;
            70    int i;
            71    DNANumber dnaArray[10000];
            72    //DNANumber *dna;
            73
            74    scanf("%d %d"&length, &rows);
            75    for(i = 0; i < rows; i++)
            76    {
            77        dnaArray[i].count=0;
            78        scanf("%s", dnaArray[i].ch);
            79        CountNumber(&dnaArray[i], length);        
            80    }

            81
            82    Sort(dnaArray, rows);
            83
            84    for(i = 0; i < rows; i++)
            85    {
            86        printf("%s\n", dnaArray[i].ch);
            87    }

            88    return 0;
            89}

            90
            91
            92

            posted on 2008-05-20 08:24 Leon916 閱讀(1239) 評(píng)論(1)  編輯 收藏 引用
            評(píng)論:
            • # re: acm1007探討  99dreamer Posted @ 2009-01-01 11:40
              首先謝謝你的代碼。
              你的代碼讓我找出了我的錯(cuò)誤,呵呵

              我的代碼如下:
              /*整體思想很簡(jiǎn)單,用chag函數(shù)求得每個(gè)串的逆序數(shù)返回。而主函數(shù)接收并保存。然后根據(jù)逆序數(shù)排序輸出即可*/
              #include<stdio.h>
              #include<stdlib.h>
              #include<string.h>

              int chag(char *p,int n)
              {
              int i,j,sum=0;
              for(i=0;i<n-1;i++)
              for(j=i+1;j<n;j++)
              if(*(p+i)>*(p+j))
              sum++;
              return sum;
              }

              int main(void)
              {
              int n,m,i,j,t,sav[100];
              char pre[101][51],cop[51];
              scanf("%d %d",&n,&m);
              for(i=0;i<m;i++)
              {
              scanf("%s",pre[i]);
              sav[i]=chag(pre[i],n);
              }
              for(i=0;i<m-1;i++)
              for(j=i+1;j<m;j++)
              if(sav[i]>sav[j])
              {
              t=sav[i];
              sav[i]=sav[j];
              sav[j]=t;
              strcpy(cop,pre[i]);
              strcpy(pre[i],pre[j]);
              strcpy(pre[j],cop);
              }
              for(i=0;i<m;i++)
              printf("%s\n",pre[i]);

              system("PAUSE");
              return 0;
              }
                回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


             
            Copyright © Leon916 Powered by: 博客園 模板提供:滬江博客
            久久中文字幕人妻熟av女| 精品国产乱码久久久久久呢| 久久免费视频1| 7777精品久久久大香线蕉| 99久久免费国产特黄| 国产高潮国产高潮久久久91| 精品久久综合1区2区3区激情 | 色综合久久中文色婷婷| 久久久久噜噜噜亚洲熟女综合| 久久人人爽人人爽人人片AV东京热 | 久久久久久久精品成人热色戒| 亚洲国产成人久久综合一区77| 国产精品成人久久久| 久久国产精品成人片免费| 亚洲精品无码久久千人斩| 久久国产精品成人免费| 久久不见久久见免费视频7| 久久精品国产精品亚洲精品 | 久久ZYZ资源站无码中文动漫| 久久国产欧美日韩精品免费| 久久精品?ⅴ无码中文字幕| 欧美午夜精品久久久久久浪潮| 久久99精品国产99久久6男男| 国产成人精品白浆久久69| 国产精品视频久久久| 亚洲国产精品婷婷久久| 国产精品狼人久久久久影院| 欧美麻豆久久久久久中文| 久久精品国产精品亚洲精品| 久久99精品久久久久子伦| 久久免费高清视频| 亚洲精品国产第一综合99久久| 无码国内精品久久人妻蜜桃 | 狠狠人妻久久久久久综合| 久久99久久无码毛片一区二区| 久久婷婷五月综合97色直播| 国内精品久久人妻互换| 亚洲人成无码网站久久99热国产| 国产伊人久久| 日韩久久久久久中文人妻| 国产免费久久精品99久久|