Sort a List of 20 Names
The user enters 20 names (or whatever) into an array and the program outputs the 20 inputs alphabetically. The program also stops and sorts what the user has entered so far if the user does not enter anything.
AI
สรุปโดย AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
ซอร์สโค้ด
/* By Dfuse http://dfuse.netfirms.com [email protected] */ #include<iostream.h> #include <string.h> void getName(char* name) { cout<<"Enter a Name: "; cin.getline(name, 20, '\n'); if(strlen(name)==19) cin.ignore(100,'\n'); } //getName readAllNames(char list [] [20]) { int i=0; getName(list[i]); while((i<19)&&(strlen(list[i])>0)) { i++; getName(list[i]); } //while return i+1; }//readAllNames void printAll(char list[][20],int c) { for (int i=0;i<c;i++) cout<<list[i]<<"\n"; } //printAll void swap(char *s1, char *s2) {char* temp; strcpy(temp,s1); strcpy(s1,s2); strcpy(s2,temp); } //swap sort(char list[][20], int n) { int i, smallPos, pass; char temp; for (pass=0; pass<n; pass++) { smallPos = pass; for (i=pass; i<n; i++) { if (stricmp (list[i], list[smallPos])< 0) smallPos = i; } //for swap(list[smallPos], list[pass]); } //for return; } main() { char names[20][20]; int count=0; count=readAllNames(names); //cout<<"Count= "<<count<<"\n"; sort(names,count); printAll(names,count); return 0; } //main Function Encrypt(TextIn:string;Key:string):string; Var I,I2,Val,KeyLen: integer; begin KeyLen := length(Key); I2 := 1; For I := 1 to length(TextIn) do Begin Inc(I2,1); If I2 > KeyLen then Begin I2 := 1; End; Val := (ord(TextIn[I]) XOR ord(Key[I2])); Result := Result + char(Val); End; End;
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine