write a code to sort string

조회 수: 14(최근 30일)
Aminata camara
Aminata camara 2021년 3월 17일
댓글: Aminata camara 2021년 3월 18일
how to I write a code for this problem:
Write a program that accepts a string from a user with the input function, chops that string into a series of tokens, sorts the tokens into ascending order, and prints them out.
this is what I wrote so far I dont know what to do
%Input a user string
str=input('Enter string:','s');
[token,remain]=strtok(str,',')
  댓글 수: 2
Aminata camara
Aminata camara 2021년 3월 17일
that what the problem is saying, I understand it like when I'm writting a series of world
example if a user enter : anna,mimi,jen
the user will get
'anna'
'mimi'
'jen'
also I dont get what the problem is saying by then sort that information.

댓글을 달려면 로그인하십시오.

답변(1개)

ANKUR KUMAR
ANKUR KUMAR 2021년 3월 17일
str=input('Enter string:','s');
strsplit(str,',')
On which basis you wish to sort strings? Is it alphabatically, or based on the length ?
  댓글 수: 9
Aminata camara
Aminata camara 2021년 3월 18일
ooh I see now thank you for the great explanation

댓글을 달려면 로그인하십시오.

범주

Find more on Characters and Strings in Help Center and File Exchange

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by