#28762: 請問為什麼第一個測資會錯?


joey13130905@gmail.com (笨呆瓜)

學校 : 淡江大學
編號 : 89206
來源 : [1.163.240.33]
最後登入時間 :
2023-11-06 14:53:44
c012. 10062 - Tell me the frequencies! -- UVa10062 | From: [114.35.245.150] | 發表日期 : 2021-12-31 14:04

#0: 100% WA (line:1)

您的答案為: 255 1
正確答案為: 67 1

#include <stdio.h> #include <string.h> int main(){ char line[1000]; int count[127] = {0}; gets(line); for(int i = 0;i < strlen(line);i++) count[line[i]]++; int max = 0; for(int i = 0;i < 127;i++){ if(max < count[i]) max = count[i]; } for(int i = 1;i <= max;i++){ for(int k = 127;k >= 0;k--){ if(count[k] == i) printf("%d %d\n",k,i); } } return 0; }

 

 
#28766: Re:請問為什麼第一個測資會錯?


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
c012. 10062 - Tell me the frequencies! -- UVa10062 | From: [27.51.89.147] | 發表日期 : 2021-12-31 15:11

 

        for(int k = 127;k >= 0;k--){
            if(count[k] == i)
                printf("%d %d\n",k,i);
        }
    


count陣列範圍是0到126你這樣超出範圍了

而且這題有多比測資

 
ZeroJudge Forum