24h購物| | PChome| 登入
2009-11-14 19:22:05| 人氣968| 回應0 | 上一篇 | 下一篇

95高市資訊學科能力競賽 K-間隔 (K-GAP) 子字串

推薦 0 收藏 0 轉貼0 訂閱站台

作法:模擬

當初看不懂題目 所以一直沒寫 XD

/****************************************************/

#include<stdlib.h>
#include<stdio.h>
#include<string.h>
main()
{
  int k;
  char s[2001];
  while(scanf("%d %s",&k,s)==2)
       {
         int a,b,c,d,time=0,n=strlen(s);
           for(a=0;a<n;a++)
                 for(b=1;a-b>=0;b++)
                     {
                         for(c=a-b,d=a+k;c<a;c++,d++)
                             if(s[c]!=s[d]) break;
                         if(c==a) time++;
                     }
         printf("%d\n",time);
       }
  return 0;
}

台長: 來源不明

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文