View Code of Problem 36

#include<bits/stdc++.h>      
using namespace std;
#define max 1001
int main(){    
	char a[max];
	int n,num[100] = { };
	cin>>n;
	getchar();
	for(int i = 0;i<n;i++){
		gets(a);   //随便读一个字符串 
		for(int i = 0;i<strlen(a);i++)num[a[i]]++; //取一个字符 放到对应的下标里  A 65
		//  num下标代表写字母的阿斯克码  num内容就是这个字母出现了几次 
		for(int i = 65;i<=90;i++){    //这里就是打印了 A 65 ----》 Z-90 
			if(num[i]!=0){
				cout<<num[i]<<(char)i;
			}
		}
		if(i!=n-1)cout<<endl;	   
		memset(num,0,sizeof(num));    //清空数组 
		memset(a,0,sizeof(a));
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 36