1071. Speech Patterns (25)

点击打开链接

2个点超时,sad。。。

注意

1.大写字母的ascii值比小写字母小32

2.字符数组的赋值用strcpy()函数

strcpy(字符数组1,字符数组2)    --即将后面的赋值给前面的


#include <cstdio>
#include <map>
#include <string>
#include <string.h>
using namespace std;
char c[1048576];
char ans[1048576];
char tmp[1048576];
int times=0;
map <string,int> mp;
int main(){
	freopen("in.txt","r",stdin);
	gets(c);
	int cnt=0;
	for(int i=0;i<=strlen(c);){
		if(c[i]>='0'&&c[i]<='9' || c[i]>='a'&&c[i]<='z' || c[i]>='A' && c[i]<'Z'){
			if(c[i]>='A' && c[i]<'Z'){
				tmp[cnt++]=c[i++]+32;
			}else{
				tmp[cnt++]=c[i++];
			}
		}else if(c[i]==' ' || c[i]=='\0'){
			tmp[cnt]='\0';
			if(strlen(tmp)!=0){
				map <string,int>::iterator it=mp.find(tmp);
				if(it!=mp.end()){
					it->second++;
				}else{
					mp[tmp]=1;
				}
			}
			i++;
			cnt=0;
			if(mp[tmp]>times){
				times=mp[tmp];
				//strcoy(字符数组1,字符数组2)即将字符数组2的内容复制到字符数组1中
				strcpy(ans,tmp);
			}
		}else{
			i++;
		}
	}
	printf("%s %d\n",ans,times);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值