hdu 1860统计字符

时间:2023-03-09 19:37:00
hdu 1860统计字符

本来是想用map写的,但是map里面会自动按字典序升序排序导致wa了一把,供

 #include<time.h>
#include <cstdio>
#include <iostream>
#include<iterator>
#include<algorithm>
#include<math.h>
#include <string.h>
#include<vector>
#include<queue>
#include<map>
typedef long long int ll;
using namespace std; /*
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
*/ char c[],d[];
map<char,int> m_map; int main()
{
int len1,len2,sum;
while(gets(c))
{
if(c[]=='#')
break;
gets(d);
len1=strlen(c);
len2=strlen(d);
//m_map.clear();
for(int i=;i<len1;i++)
{
sum=;
for(int j=;j<len2;j++)
{
if(c[i]==d[j])
sum++;
}
printf("%c %d\n",c[i],sum);
}
/*
map<char,int>::iterator it=m_map.begin();
for(it;it!=m_map.end();it++)
cout<<it->first<<" "<<it->second<<endl;
*/
}
return ;
}

参考