이 숙제를위한 가정 (그리고 혼자서이 일을, 아니라면 그냥 대답을 보는 것보다 당신에게 더 많은 도움이 될 것입니다) 나는 그냥 당신을 도와 당신에게 몇 가지 조언 해 줄거야 . ASCII 값에 대한
aPlayer player1, player2;
player1.name = "bill";
player2.name = "john";
if (player1.name[0] < player2.name[0])
{
// True, in this case, because b is less than j on the ascii table.
}
http://www.asciitable.com :
은 ASCII 값을 비교. 대문자는 소문자보다 낮은 값이므로 플레이어 이름에 tolower()를 사용하는 것이 좋습니다. 첫 번째 디지트가 같으면
번째로 이동 : . (이를위한 한 가지 방법)
aPlayer player1, player2;
player1.name = "alfred";
player2.name = "alvin";
// Find which name is shorter using .length() like player2.name.length()
// Loop through this next part for all aPlayers in aCompetition
for (int i = 0; i < shorterName.length(); i++)
{
// Compare ascii values as I showed above.
// If one is larger than the other, swap them.
}
STD : 문자열 지원보다 덜하고보다 큰 비교. std :: sort를 사용 하겠지만 간단한 버블 정렬을 사용할 수있는 것으로 제한되어 있다면 괜찮을 것이며 쉽게 알고리즘을 찾을 수 있습니다. –
aCompetition이 실제로 구조체 여야합니까? 그것은 배열을 보유하고 고려 중입니까? – Krythic
나에게 완벽하게 정상적으로 보입니다. 경쟁에는 플레이어가 포함됩니다. –