1.将一个整数用字符串表示,该整数可以是负数
例:i = 123;
output = "123"
void fun(const int input,char *output)
{}
2.倒置单链表
typedef struct LNode{
int data;
struct LNode *next;
}LNode;
例:
1->2->3
3->2->1
链表数据结构
void fun(LNode **Head)
{}
3.查询一个字符串中出现频率最高和最低的单词,频率相同的选首次出现的.
字符串中只出现四种:逗号,句号,空格,大写字母,小写字母,
两个单词中只有大小写不同,算作同一个单词,记小写单词
例:"some students some boys some baby"--->"some","students"//
void fun(const char *InputStr, char *Output1, char *Output2)
/*void main()
{
char Inputstr[] = {"some students some boys some baby"};
char Out1[32];
char Out2[32];
fun(InputStr, out1, out2);
//下面就是字符串输出
}*/给的main函数大致如此
我的函数代码:
//#include <stdlib.h>
//#include <string.h>
void fun(const char *InputStr, char *Output1, char *Output2)
{
const char *p = InputStr;
char word[50][32];
int w[50] = {0};
char temp[50];
int k = 0;
int m = 0;
int i = 0;
while (*p != '\0')
{
k = 0;
while (*p!=' ' && *p!=',' && *p!='.' && *p!='\0')
{
if (*p>='A' && *p<='Z')
temp[k++] = *p + 'a' - 'A';
else
temp[k++] = *p;
p++;
}
if (k > 0)
{
temp[k] = '\0';
for (i=0; i<m; i++)
if (!strcmp(word[i], temp))
w[i]++;
if (i>=m)
{
strcpy(word[m], temp);
w[m++] = 1;
}
}
p++;
}
int min=0;
int max=0;
for (i=0; i<m; i++)
{
if (w[i] > w[max])
max = i;
if (w[i] < w[min])
min = i;
}
strcpy(Output1, word[min]);
strcpy(Output2, word[max]);
}
转载于:https://blog.51cto.com/divinechen/667336