查找最大元素
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 38 Accepted Submission(s) : 5
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
abcdefgfedcba xxxxx
Sample Output
abcdefg(max)fedcba x(max)x(max)x(max)x(max)x(max)
Author
Source
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
//還有一個問題,總是當成java提交了
using namespace std;
char x[10000];
int main()
{
int max,i,j,k,len;
while(scanf("%s",x)!=EOF)
{
max=0;//記錄最大的位置
len=strlen(x);
//找到最大
for(i=0;i<len;i++)
{
if(x[i]>x[max])
max=i;
}
for(i=0;i<len;i++)
{
printf("%c",x[i]);//不論什麼樣都先輸出
if(x[i]==x[max])//每一次都輸出,開始只是第一次輸出了
printf("(max)");//不用存儲
}
printf("\n");
memset(x,'\0',sizeof(x));
}
return 0;
}