當前位置:首頁 » 編程語言 » C語言pta

C語言pta

發布時間: 2023-07-26 15:01:04

1. PTA中C語言編程問題(答案沒有給我滿分,請幫我指出一下我程序的錯誤)

#include<stdio.h>
intmain()
{
intn,a[11],i,temp,j;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(j=0;j<n;j++)
for(i=0;i<n-j-1;i++)//改了下這里當i=n-1時i+1就越界了,所以i<n-j-1
if(a[i]<a[i+1])
{temp=a[i];a[i]=a[i+1];a[i+1]=temp;}
for(i=0;i<n-1;i++)
printf("%d",a[i]);
printf("%d",a[i]);
return0;
}

2. PTA的C語言題

#include<stdio.h>

intcount[1000];//統計數組,下標為菜品標號,對應數值為菜品數量

intmain(){
intn,t,i,max=0;
scanf("%d",&n);
while(scanf("%d",&t)!=EOF){
count[t-1]++;
max=(max<=count[t-1])?count[t-1]:max;//尋找最多的菜品
}
for(i=0;i<n;i++){
if(count[i]==max)printf("%d%d ",i+1,count[i]);
}
}

熱點內容
編輯html源碼 發布:2025-05-16 17:45:45 瀏覽:64
邊的存儲方法 發布:2025-05-16 17:33:16 瀏覽:926
海量伺服器怎麼拆 發布:2025-05-16 17:31:07 瀏覽:210
運行與編譯的區別 發布:2025-05-16 17:25:02 瀏覽:823
c語言for中continue 發布:2025-05-16 17:20:14 瀏覽:648
ftp儲存 發布:2025-05-16 17:04:08 瀏覽:504
家悅3010怎麼看電腦配置 發布:2025-05-16 17:02:38 瀏覽:885
sqlin傳參 發布:2025-05-16 17:02:37 瀏覽:890
python計算md5 發布:2025-05-16 17:02:32 瀏覽:427
看演算法頭疼 發布:2025-05-16 16:56:41 瀏覽:798