📄 2405073_ac_15ms_176k.c
字号:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INIT (Tree *)malloc(sizeof(Tree))
typedef struct node
{
int app;
char word[100];
struct node *l, *r;
}Tree;
Tree *head;
int mark = 1, max = 1;
int is(char ch)
{
if(ch<='Z'&&ch>='A')
return 1;
if(ch>='a'&&ch<='z')
return 1;
if(ch<='9'&&ch>='0')
return 1;
return 0;
}
void insert(char word[])
{
Tree *s, *p;
if(mark)
{
head = INIT;
head->app = 1;
mark = 0;
strcpy(head->word,word);
head->l = head->r = NULL;
}
else
{
s = head;
p = INIT;
p->app = 1;
strcpy(p->word,word);
p->l = p->r = NULL;
while(s)
{
if(strcmp(s->word,word)>0)
if(s->l)
s = s->l;
else
{
s->l = p;
break;
}
else
if(strcmp(s->word,word)<0)
if(s->r)
s = s->r;
else
{
s->r = p;
break;
}
else
{
s->app++;
if(s->app>max)
max = s->app;
break;
}
}
}
}
void solve(Tree *s)
{
if(s->l)
solve(s->l);
if(s->app==max)
puts(s->word);
if(s->r)
solve(s->r);
}
int main()
{
int i;
char word[100], tmp[100];
while(scanf("%s",word)==1)
{
for(i = strlen(word)-1; i >= -1; i--)
{
if(i>-1&&word[i]<='Z'&&word[i]>='A')
word[i] += 32;
if(i==-1||!is(word[i]))
{
strcpy(tmp,&word[i+1]);
word[i] = '\0';
if(strlen(tmp))
insert(tmp);
}
}
}
printf("%d occurrences\n",max);
solve(head);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -