#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX 1000
void swap(char *a, char *b, int *c, int *d){
int sw;
char chsw;
sw = *c;
*c = *d;
*d = sw;
chsw = *a;
*a = *b;
*b = chsw;
}
int main(){
int size, i, j, strsize;
char str[MAX];
while(scanf("%d", &size) == 1){
char let[27] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ\0"};
int count[26] = {0};
for(i = 0; i <= size; ++i){
fgets(str, MAX, stdin);
strsize = strlen(str) - 1;
for(j = 0; j < strsize; ++j){
if(islower(str[j]) != 0)
str[j] = toupper(str[j]);
count[str[j] - 65]++;
}
}
for(i = 0; i < 25; i++){
for(j = 0; j < 25-i; ++j){
if(count[j] < count[j+1])
swap(&let[j], &let[j+1], &count[j], &count[j+1]);
}
}
for(i = 0; i < 26; ++i){
if(count[i] != 0)
printf("%c %d\n",let[i],count[i]);
}
}
return 0;
}
#include
#include
#include
#include
#define MAX 1000
void swap(char *a, char *b, int *c, int *d){
int sw;
char chsw;
sw = *c;
*c = *d;
*d = sw;
chsw = *a;
*a = *b;
*b = chsw;
}
int main(){
int size, i, j, strsize;
char str[MAX];
while(scanf("%d", &size) == 1){
char let[27] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ\0"};
int count[26] = {0};
for(i = 0; i <= size; ++i){
fgets(str, MAX, stdin);
strsize = strlen(str) - 1;
for(j = 0; j < strsize; ++j){
if(islower(str[j]) != 0)
str[j] = toupper(str[j]);
count[str[j] - 65]++;
}
}
for(i = 0; i < 25; i++){
for(j = 0; j < 25-i; ++j){
if(count[j] < count[j+1])
swap(&let[j], &let[j+1], &count[j], &count[j+1]);
}
}
for(i = 0; i < 26; ++i){
if(count[i] != 0)
printf("%c %d\n",let[i],count[i]);
}
}
return 0;
}
strsize = strlen(str) - 1;
for(j = 0; j < strsize; ++j){ //這行出問題
改成for(int j = 0; j < strlen(str); ++j) {
或是for(j = 0; j <= strsize; ++j){