码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2945

时间:2014-08-10 18:25:40      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   strong   for   

accept

bubuko.com,布布扣
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;

char ss[20005][25];
int num[20005];
int n,m;

int cmp(const void * a,const void * b)
{
    int i,ans;
    char *s1,*s2;
    s1=(char *)a;
    s2=(char *)b;
    for(i=0;i<m;i++)
    {
        ans=s1[i]-s2[i];
        if(ans==0)
           continue;
        else
           return ans;
    }
    return ans;
}

int main()
{
    int i,j,sum;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==0&&m==0)
           break;
        for(i=0;i<n;i++)
           scanf("%s",ss[i]);
        qsort(ss,n,sizeof(ss[0][0])*25,cmp);
        memset(num,0,sizeof(num));
        for(i=1,sum=0;i<=n;i++)
        {
            if(strcmp(ss[i],ss[i-1])==0)
               sum++;
            else
            {
                num[sum]++;
                sum=0;
            }
        }
        for(i=0;i<n;i++)
           printf("%d\n",num[i]);
    }
    return 0;
}
View Code

 

#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;

char ss[20005][25];
int num[20005];
int n,m;

int cmp(const void * a,const void * b)
{
int i,ans;
char *s1,*s2;
s1=(char *)a;
s2=(char *)b;
for(i=0;i<m;i++)
{
ans=s1[i]-s2[i];
if(ans==0)
continue;
else
return ans;
}
return ans;
}

int main()
{
int i,j,sum;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0)
break;
for(i=0;i<n;i++)
scanf("%s",ss[i]);
qsort(ss,n,sizeof(ss[0][0])*25,cmp);
memset(num,0,sizeof(num));
for(i=1,sum=0;i<=n;i++)
{
if(strcmp(ss[i],ss[i-1])==0)
sum++;
else
{
num[sum]++;
sum=0;
}
}
for(i=0;i<n;i++)
printf("%d\n",num[i]);
}
return 0;
}

 bubuko.com,布布扣bubuko.com,布布扣

 

 

 

 

 

 

 

Time Limit Exceeded===pku 2945

 

=Time Limit Exceeded *
*********************

 

#include <iostream>
#include <map>
#include <cstring>
#include <string>
using namespace std;
map<string,int> my;
int a[100005];
int main(int argc, char *argv[])
{
int n,m,i,j; string s;
while(cin>>n>>m)
{
for(i=0;i<n;i++)
{
cin>>s;
if(my.count(s)==0) my[s]=1;
else my[s]++;
}
memset(a,0,sizeof(a));
map<string,int> ::iterator it;
for(it=my.begin();it!=my.end();it++)
{
int x=(*it).second;
a[x]++;
}
for(i=1;i<=n;i++)
{
cout<<a[i]<<endl;
}
my.clear();
}
return 0;
}

 

 

 

 

 


*********************************************************************************************************************

************************************************************************************************************************

 

#include <algorithm>
using namespace std;
#define MAX 20000
int A[MAX],ans,C[MAX];
map <string,int> mp;
int ID(string s){
if(mp[s]>0)return mp[s]-1;
mp[s]=ans++;
return ans-2;
}
int main(){
string s;
int n,m;
while(scanf("%d%d",&n,&m)==2 && n && m){
ans=1;
mp.clear();
memset(A,0,sizeof(A));
for(int i=0;i<n;i++){
cin>>s;
A[ID(s)]++;
}
memset(C,0,sizeof(C));
for(int i=0;i<n;i++)
C[A[i]]++;
for(int i=1;i<=n;i++)
printf("%d\n",C[i]);
}
return 0;
}

 

poj 2945,布布扣,bubuko.com

poj 2945

标签:style   blog   http   color   os   io   strong   for   

原文地址:http://www.cnblogs.com/2014acm/p/3903086.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!