11203-眾數
題目描述(Description)
眾數是指在一組數據中,出現次數最多的數。例如:1, 1, 3 中出現次數最多的數為 1,則眾數為 1。 給定一組數,你能求出眾數嗎?
輸入格式(Format Input)
第 1 行輸入一個整數 n (1 <= n <= 10000),表示數的個數。
第 2 行輸入 n 個用空格隔開的整數 Ai (0 <= Ai <= 1000),依次表示每一個數。
輸出格式(Format Output)
在一行中輸出一個整數,表示這組數據的眾數。
數據保證有唯一的眾數。
輸入樣例 1(Sample Input 1)
3
1 1 3
輸出樣例 1(Sample Output 1)
1
限制(Restrictions)
時間限制(Time Limit): 1000 ms
內存限制(Memory Limit): 65536 KB
說明/提示
#include<bits/stdc++.h>
using namespace std;
int a[10001];
int main(){int n,num;int max=0,ans;cin>>n;for(int i=1;i<=n;i++){cin>>num;a[num]++;if(a[num]>=max){max=a[num]++;ans=num;}}cout<<ans;return 0;
}
1113-字母統計
題目描述(Description)
小朋友在幼兒園的時候沒有學過英語,只認識 26 個字母。所以拿到一個句子,就之后做一件事情,就是數字母。那個,作為學生的你,如果給你一個句子,你能輸出其中每個字母的個數么?
輸入格式(Format Input)
第一行包括一個整數,表示句子的長度,長度不會超過 100。
第二行包括一個句子
輸出格式(Format Output)
按順序輸出每個出現的小寫字母的個數
輸入樣例 1(Sample Input 1)
21
pascalissointeresting
輸出樣例 1(Sample Output 1)
a 2
c 1
e 2
g 1
i 3
l 1
n 2
o 1
p 1
r 1
s 4
t 2
限制(Restrictions)
時間限制(Time Limit): 1000 ms
內存限制(Memory Limit): 65535 KB
說明/提示
#include<bits/stdc++.h>
using namespace std;
int a[27];
int main(){int n;
// char str;cin>>n;for(int i=1;i<=n;i++){char str;cin>>str;a[str]++; }for(char i='a';i<='z';i++){if(a[i]!=0){cout<<i<<" "<<a[i]<<endl;} }return 0;
}