вот, не проверял особо, но должно работать...
| Код | #include <iostream> #include <fstream> #include <cstring>
using namespace std;
void Lowercase(char *arr) { int len = strlen(arr); for(int i = 0; i < len; i++) tolower(arr[i]); }
void BubbleSort(char (*arr)[256], int size) { char temp[256] = {'\0'}; for(int i = 1; i < size; ++i) for(int j = 0; j < size - i; ++j) if ( (strcmp(arr[j], arr[j+1]) > 0) ) { strcpy(temp, arr[j]); strcpy(arr[j], arr[j+1]); strcpy(arr[j+1], temp); } }
int main() { char words[256][256] = {'\0'}; char word[256] = {'\0'}; int count = 0;
ifstream in("C:\\in.txt"); ofstream out("C:\\out.txt");
if(!in) { cout << "Error\n"; return 1; }
in.unsetf(ios::skipws);
while(!in.eof()) { char *p; in.getline(word, 256);
p = strtok(word, " "); while(p != NULL) { strcpy(words[count++], p); p = strtok(NULL, " "); }
BubbleSort(words, count);
for(int index = 0; index < count ; index++) { Lowercase(words[index]); words[index][0] = toupper(words[index][0]); out << words[index] << ' '; memset(words[index], '\0', 32); } out << '\n'; count = 0; }
in.close(); out.close();
return 0; }
|
Добавлено @ 19:56 если используешь Borland 3.1 или что-то типа того, то вместо
| Код | #include <iostream> #include <fstream> #include <cstring>
using namespace std;
|
надо написать
| Код | #include <iostream.h> #include <fstream.h> #include <string.h>
|
|