字符串中最长单词

时间:2021-01-29 12:05:24   收藏:0   阅读:0
样例输入
I am a student
样例输出
student
 1 #include <stdio.h>
 2 #include <string.h>
 3 int main()
 4 {
 5     char a[100005], b[100005];
 6     int i, num = 0;
 7     while (scanf("%s", &a) != EOF) {
 8         if (num < strlen(a)) {
 9             num = strlen(a);
10             for (i = 0; i < num; i++) b[i] = a[i];
11         }
12         puts(a);//参考
13     }
14     puts(b);
15     return 0;
16 }

输入

  I am a student

输出

  I am a student
  I
  am
  a
  student
  ^Z
  student

 
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!