C language Teaching notes--alphabetical order

Source: Internet
Author: User

When a person is told how a problem should be solved, and the results of a personal experiment OK, once encountered a similar problem, it will be conditioned directly to use this method. It is very rare to think about why this method, whether there is any hidden danger, there is no other way, and so on these problems.

At least that's what I am.

This semester, C language class, originally out of the topic let students put arbitrary strings in alphabetical order to output, is to let them practice the sorting algorithm.

One of the programs that a student handed in was this:

#include <stdio.h>#include<string.h>intMain () {Charch[ -],_mark;inti,n;scanf ("%s", ch); n=strlen (CH); _mark='A'; while(_mark<='Z'){     for(i=0; I {if(ch[i]==_mark) printf ("%c", Ch[i]); } _mark++;}return 0;}

It was clear that her idea was to traverse the string 26 times, starting with the smallest ' a ' to traverse through the same output, and then using ' B ' to traverse until the last capital letter ' Z '.

After I had probably mentioned the idea of sequencing, she thought about the output. Although the adaptability of this algorithm and the time complexity of the algorithm are very high, and from the point of view of the two evaluation procedures, the program is even slightly clumsy. But, it wins in easy to understand and ingenuity, really is let me pleasantly surprised!!

C language Teaching notes--alphabetical order

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.