Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6683067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:46:41+00:00 2026-05-26T04:46:41+00:00

This is what I’m up to so far char max = 0, here; while(scanf(%c,

  • 0

This is what I’m up to so far

char max = 0, here;
while(scanf("%c", &here) == 1 && here != '\n')
    if(here > max)
        max = here;
printf("max='%c'\n", max);

The user could enter a sequence of characters, and I’d get back the letter with the highest ASCII value. In Computer Fun, this would be u. But if CompUter Fun were the input, I’d want to get U back because it has been entered first in the sequence.

I could have two variables saving the highest capital letter and the highest simple letter, but how would I then know which came first?

Thanks in advance. Explaining the logic is just fine, if you don’t want to write out the code fragment that does this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:46:42+00:00Added an answer on May 26, 2026 at 4:46 am

    You only need one variable—just keep track of the character that wins up to this point.

    As you scan over the input CompUter Fun, you first see C. Since its the first character, its the winner so far. Then you see o. o comes after C, so its now the winner; your variable now contains o. And so on. You only replace the stored character if the new one wins, so you’ll get the first one in case of ties.

    (When comparing, you need to do a case-insensitive compare; an easy way to do this is tolower on both sides of the compare).

    input  winner
    C      C       # first letter always wins
    o      o       # o > c
    m      o       
    p      p       # p > o
    U      U       # U > o
    t      U
    e      U
    r      U
           U       # space
    F      U
    u      U       # u == U, so !(u > U), so U stays winner
    n      U
    

    gives the ultimate winner, U.

    This is an efficient general algorithm for finding the maximum (or minimum, by reversing the compare) of an unordered input. It can also be extended to keep track of 2nd (etc.) place, though at some point sorting becomes more efficient, especially on data like this where you can use radix O(n) sorts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This is my first post here and I wanted to get some input from
This isn't about the different methods I could or should be using to utilize
this is what i have so far: type u = {str : string} //some
This is beyond both making sense and my control. That being said here is
This is how my web page looks like: PosisionDataView is a web user control,
This is a bit of a long shot, but if anyone can figure it
This is starting to vex me. I recently decided to clear out my FTP,
This is kinda oddball, but I was poking around with the GNU assembler today

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.