有没有人在啊,想请讲解下,请高手帮忙把代码调试成功并注释(云计算),急急急!在线等 答得好分数可追加!?
#include <stdio.h>#include <string.h>
#include <stdlib.h>
#define BUF_SIZE 2048
int my_map(char *buffer,char (*mapbuffer)[100]);
int my_reduce(char (*mapbuffer)[100],char (*reducebuffer)[100],int *count,int num);
int main(int argc,char *argv[])d
{
char buffer[BUF_SIZE];
char mapbuffer[BUF_SIZE][100];
char reducebuffer[BUF_SIZE][100];
int count[BUF_SIZE]={0};
int num;
int i;
int countnum;
fgets(buffer,BUF_SIZE-1,stdin);
buffer[strlen(buffer)-1]='\0';
num=my_map(buffer,mapbuffer);
printf("this is map results:\n");
for(i=0;i<num;i++)
{
printf("<%s\t1>\n",mapbuffer[i]);
}
countnum=my_reduce(mapbuffer,reducebuffer,count,num);
printf("this is reduce results:\n");
for(i=0;i<countnum;i++)
{
printf("<%s\t%d>\n",reducebuffer[i],count[i];
}
}
int my_map(char *buffer, char(*mapbuffer)[100])
{
char *p;
int num=0;
if(p=strtok(buffer, " ")
{
strcpy(mapbuffer[num],p);
num++;
}
else
return num;
while(p=strtok(NULL,""))
{
strcpy(mapbuffer[num],p);
num++;
}
return num;
}
int my_reduce(char (*mapbuffer)[100], char(*reducebuffer)[100],int *count,int num)
{
int i,j;
int flag[BUF_SIZE]={0};
char tmp[100];
int countnum=0;
for(i=0;i<num;i++)
{
if(flag[i]==0)
{
strcpy(tmp,mapbuffer[i]);
flag[i]=1;
strcpy(reducebuffer[countnum],mapbuffer[i]);
count[counnum]=1;
for(j=0;j<num;j++)
{
if(memcmp(tmp,mapbuffer[j],strlen(tmp))==0 && (strlen(tmp)==strlen(mapbuffer[j]))&& (flag[j]==0)
{
count[countnum]++;
flag[j]=1;
}
}
countnum++;
}
}
return countnum;
}
输入: this is map reduce hello map hello reduce
求注释,重点是注释,麻烦大侠补充一下,不胜感激!!!