这个题目主要是在一串字符串中寻找最大字符,
并在其后面插入"(max)",
如果max有多个,就群补都要插入,
把数组后移太麻烦了,所以要用取巧的方法,
直接在max后面printf,
虽然这个题目很简单,但是在编译的时候还是出来点麻烦,
就是在输入字符串的时候,我选择了用
while (getchar ())
gets (str);
虽然也可以实现,但是结果却是“Output Limit Exceeded"
花费时间太长了,
所以最好是用
while (scanf ("%s", str) != EOF), 节约了很多时间,
呵呵,终于知道他们俩的差别了,呼呼~
以下就是代码:
#include <stdio.h>
#include <string>
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
int i, j;
char str[100];
while (scanf ("%s", str) != EOF)
{
int len = strlen(str), max = str[0];
for (i = 1; i < len; i ++)
{
if (str[i] > max)
{
max = str[i];
}
}
for (j = 0; j < len; j ++)
{
printf ("%c", str[j]);
if (str[j] == max)
printf ("(max)");
}
printf ("\n");
}
system ("pause");
return 0;
}