Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:第一次发代码,很挫,大家见谅!已经AC了哦

Posted by chunjingshui at 2013-04-25 16:39:39 on Problem 1007
In Reply To:第一次发代码,很挫,大家见谅!已经AC了哦 Posted by:xiaodaodao at 2013-03-27 10:28:43
> /*
>   采用标记法:当出现C时候,c_flag = 1,那么后面扫描到A的时候,判断此标记是否为1,当再次出现C时候,c_flag++,因为多了一个C在前面,呵呵~ 
>   是则count++,当出现G时候,g_flag = 1, 那么当后面出现C和A时候,判断此标记是否为1,当再次出现C时候,g_flag++,因为多了一个G在前面,呵呵~ 
>   是则count++,当出现T时候,t_flag = 1, 那么当后面出现C,A,G时候,判断此标记是否为1,当再次出现T时候,t_flag++,因为多了一个T在前面,呵呵~ 
> */
> 
> // A 最小,所以不需要~ 
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> 
> typedef struct 
> {
>     int w;        // 权值 
>     char str[50];
> }data;
> 
> int cmp( const void * a, const void * b )
> {
>     return ( (*(data*)a).w - (*(data*)b).w );
> }
> 
> int main()
> {
>     int c_flag = 0;
>     int g_flag = 0;
>     int t_flag = 0;
>     int i, n, m, j, t;
>     data d[100];
>     
>     while( scanf("%d%d", &n, &m) != EOF )
>     {
>          getchar();
>          i = -1;
>          t = m;
>          while( m-- )
>          {
>              c_flag = 0;    
>              g_flag = 0;
>              t_flag = 0;
>              gets( d[++i].str );
>              
>              // 下面计算权值! 
>              j = -1;
>              d[i].w = 0;   // 初始化 
>              while( d[i].str[++j] )
>              {
>                   if( d[i].str[j] == 'A' )
>                   {
>                       if( c_flag )
>                       {
>                           d[i].w += c_flag;
>                       }
>                       if( g_flag )
>                       {
>                           d[i].w += g_flag;
>                       }
>                       if( t_flag )
>                       {
>                           d[i].w += t_flag;
>                       }
>                   }
>                   else if( d[i].str[j] == 'C' )
>                   {
>                       c_flag++;
>                       if( g_flag )
>                       {
>                           d[i].w += g_flag;
>                       }
>                       if( t_flag )
>                       {
>                           d[i].w += t_flag;
>                       }
>                   }
>                   else if( d[i].str[j] == 'G' )
>                   {
>                        g_flag++;
>                        if( t_flag )
>                        {
>                           d[i].w += t_flag;
>                        }
>                   }
>                   else if( d[i].str[j] == 'T' )
>                   {
>                        t_flag++;
>                   }
>              }
>          }
>          
>          qsort( d, t, sizeof( data ), cmp );
>          
>          for( i = 0; i < t; i++ )
>          {
>               puts( d[i].str );
>          }
>     }
>     
>     return 0;
> }
> 
> 
> 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator