Skip to content

Instantly share code, notes, and snippets.

@AhmedMourad0
Created December 21, 2017 23:35
Show Gist options
  • Save AhmedMourad0/539954bacec751c67471398955622ccc to your computer and use it in GitHub Desktop.
Save AhmedMourad0/539954bacec751c67471398955622ccc to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/PE.iml" filepath="$PROJECT_DIR$/.idea/PE.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
cmake_minimum_required(VERSION 3.8)
project(PE)
set(CMAKE_CXX_STANDARD 17)
set(SOURCE_FILES main.cpp)
add_executable(PE ${SOURCE_FILES})
#include <string> // string
#include <iostream> // cin, cout
using namespace std;
int n;
string wordsArray[10][100];
int longestWord = 0;
int lastFilledIndex[10];
char* map_number(int number) {
switch (number) {
case 1:
return const_cast<char *>("one");
case 2:
return const_cast<char *>("two");
case 3:
return const_cast<char *>("three");
case 4:
return const_cast<char *>("four");
case 5:
return const_cast<char *>("five");
case 6:
return const_cast<char *>("six");
case 7:
return const_cast<char *>("seven");
case 8:
return const_cast<char *>("eight");
case 9:
return const_cast<char *>("nine");
case 10:
return const_cast<char *>("ten");
default:
return const_cast<char *>("");
}
}
int number_char(char *s) {
return static_cast<string>(s).size();
}
int main() {
cout << "Enter n of words:\n";
cin >> n;
cout << "Enter your words:\n";
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (s.size() > longestWord)
longestWord = s.size();
int length = number_char(&s[0]);
wordsArray[length - 1][lastFilledIndex[length - 1]] = s;
++lastFilledIndex[length - 1];
}
for (int i = 0; i < longestWord; ++i) {
cout << map_number(i + 1) << "-letter words\t" << lastFilledIndex[i];
for (int j = 0; j < lastFilledIndex[i]; ++j)
cout << "\t" << wordsArray[i][j];
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment