参考代码如下:
#include <stdio.h> #include <string.h> int main(void) { char str[100]; gets(str); char* words[20]; //存放分割的字符型指针 int idx = 0; //以空格符分割字符串,存放至字符指针数组中 char *token = strtok(str, " "); while (token != NULL) { words[idx++] = token; token = strtok(NULL, " "); } //将该字符指针数组各元素所指向的字符串进行比较并排序 int i, j; for (i = 0; i < idx - 1; i++) { for (j = i + 1; j < idx; j++) { if (strcmp(words[i], words[j]) > 0) { char *tmp = words[i]; words[i] = words[j]; words[j] = tmp; } } } int num = 0; for (i = 1; i < idx; i++) { if (strcmp(words[i], words[i - 1]) != 0) num++; } if (num != 0) printf("%d\n", num + 1); else printf("%d\n", num); return 0; }
0.0分
2 人评分
WU-整除问题 (C++代码)浏览:612 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:669 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:556 |
Cylinder (C语言描述,蓝桥杯)浏览:1247 |
1014题解浏览:484 |
Tom数 (C语言代码)浏览:492 |
C二级辅导-分段函数 (C语言代码)浏览:595 |
程序员的表白 (C语言代码)浏览:591 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:678 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:740 |