24h購物| | PChome| 登入
2009-01-10 20:47:40| 人氣7,966| 回應3 | 上一篇 | 下一篇

ACM 10062 Tell me the frequencies!

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

這題我採用暴力法!因為我不知道它的ASCII碼最大為多少,所以我先設到256就好。

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

#include<stdio.h>  
#include<stdlib.h>
#include<string.h>
main()
{
 char input[1001];
 int b,c,n;
 while(gets(input)!=0)
  {
  
   int a[257]={0};                   n=strlen(input);
   for(b=0;b<n;b++)                    /*判斷並存入int陣列中*/
    {
    a[input[b]]=a[input[b]]+1;         /*個數的累加*/
    }                                 
   for(b=1;b<n;b++)                    /*從各數小*/
    {
     for(c=256;c>=0;c--)               /*ASCII大的*/
      {
       if(a[c]==b)
        printf("%d %d\n",c,b);
      } 
    }
    printf("\n");
  }
 return 0;    
}

台長: 來源不明
人氣(7,966) | 回應(3)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 數位資訊(科技、網路、通訊、家電) | 個人分類: ACM |
此分類下一篇:ACM 382 Perfection
此分類上一篇:ACM 488 Triangle Wave

Xatier
這個Code送到Uva會WA喔~~
2009-06-25 15:11:22
版主回應
修改成256呢? 會過嗎?
幫忙測試一下 ?
2009-06-25 17:39:47
路人
一樣是WA
ASCII最大其實才12X

所以可能有地方沒注意到喔
2009-12-17 19:50:48
be
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
char input[1001];
int b,c,n;
int blank = 0;
while(gets(input)!=0)
{
if( blank )
printf( "\n" );
int a[257]={0}; n=strlen(input);
for(b=0;b<n;b++)
{
a[input[b]]=a[input[b]]+1;
}
for(b=1;b<n;b++)
{
for(c=256;c>=0;c--)
{
if(a[c]==b)
printf("%d %d\n",c,b);
}
}

blank = 1;

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