int main(void) { char letter; int i, ch, flag = 0, letterFound = 0, isInput = 0, num = 0, numFirst = 0; unsigned int letterSet = 0, glasSet = 0, tmpSet = 0; for (i = 0; i < 26; i++) addToSet(&letterSet, 'a' + i); addToSet(&glasSet, 'a'); addToSet(&glasSet, 'o'); addToSet(&glasSet, 'e'); addToSet(&glasSet, 'i'); addToSet(&glasSet, 'u'); addToSet(&glasSet, 'y'); letterSet = setSubtract(letterSet, glasSet); tmpSet = glasSet; while ((ch = getchar()) != EOF) { ch = toLower(ch); if (isLetter(ch)) { isInput = 1; if (isKeyExists(letterSet, ch)) continue; if (isKeyExists(glasSet, ch)) removeFromSet(&glasSet, ch); else if (!letterFound) { letterFound = 1; numFirst = num + 1; } } else if (isSpace(ch)) { if (isInput) num++; isInput = 0; glasSet = tmpSet; } else isInput = 1; } if (letterFound) printf("Слово #%d - содержит одинаковые гласные\n", numFirst); else printf("Не найдено ни одного слова с повторяющимися гласными\n"); return 0; }
FakeSMCSensor *FakeSMCPlugin::addSensor(const char *abbriviation, kFakeSMCCategory category, UInt32 group, UInt32 index, float reference, float gain, float offset) { SYNCLOCK; FakeSMCSensor *sensor = NULL; if (abbriviation && strlen(abbriviation) >= 3) { for (int i = 0; FakeSMCSensorDefinitions[i].name; i++) { if (FakeSMCSensorDefinitions[i].category == category && 0 == strcasecmp(FakeSMCSensorDefinitions[i].name, abbriviation)) { if (FakeSMCSensorDefinitions[i].count) { for (int counter = 0; counter < FakeSMCSensorDefinitions[i].count; counter++) { char key[5]; snprintf(key, 5, FakeSMCSensorDefinitions[i].key, FakeSMCSensorDefinitions[i].shift + counter); if (!isKeyExists(key)) { sensor = addSensor(key, FakeSMCSensorDefinitions[i].type, FakeSMCSensorDefinitions[i].size, group, index, reference, gain, offset); break; } } } else sensor = addSensor(FakeSMCSensorDefinitions[i].key, FakeSMCSensorDefinitions[i].type, FakeSMCSensorDefinitions[i].size, group, index, reference, gain, offset); } } } SYNCUNLOCK; return sensor; }
/** * Synchronized method to add a new key to FakeSMCKeyStore and set its handler to the plugin * * @param abbreviation Human readable key abbreviation used in config file * @param category Category (enum kFakeSMCCategory) key belongs to so abbreviation can be checked against the list from specified category only * @param group Key group * @param index Key index not related to key position in FakeSMCKeyStore key list * @param reference Reference modifier value * @param gain Gain modifier value * @param offset Offset modifier value * * @return new FakeSMCSensor object or NULL otherwise */ FakeSMCSensor *FakeSMCPlugin::addSensorUsingAbbreviation(const char *abbreviation, FakeSMCSensorCategory category, UInt32 group, UInt32 index, float reference, float gain, float offset) { LOCK; FakeSMCSensor *sensor = NULL; if (abbreviation && strlen(abbreviation) >= 3) { for (int i = 0; FakeSMCSensorDefinitions[i].name; i++) { FakeSMCSensorDefinitionEntry entry = FakeSMCSensorDefinitions[i]; if (entry.category == category && 0 == strcasecmp(entry.name, abbreviation)) { if (entry.count) { for (int counter = 0; counter < entry.count; counter++) { char key[5]; snprintf(key, 5, entry.key, entry.shift + counter); if (!isKeyExists(key)) { sensor = addSensorForKey(key, entry.type, entry.size, group, index, reference, gain, offset); break; } } } else { sensor = addSensorForKey(entry.key, entry.type, entry.size, group, index, reference, gain, offset); } } } } UNLOCK; return sensor; }
std::string Config::getArray(const std::string& key) const { if (isKeyExists(key)) { return _map.find(key)->second; } else { return ""; } }
void Config::extractLine(const std::string& section, const std::string& line, std::ifstream& file, int& lineNb) { std::string temp = line; temp.erase(0, temp.find_first_not_of(" \t\r\n\v\f")); size_t sepPos = temp.find('='); std::string key; std::string value; extractKey(key, sepPos, temp); key = section.substr(1, section.length()-2) + "." + key; extractValue(value, sepPos, temp); if (!isKeyExists(key)) { _map.insert(std::pair<std::string, std::string>(key, value)); } else { Log(LOG_TYPE::ERROR) << "Config: Can only have unique key names!"; } }
void find_apt(COMMAND cmd, ApartmentTable db) { /* * find_apt * Printing the apartments that matched the cmd->kwargs filter */ // Pre sorting the array tto enable sorting view BOOL isAllocated = FALSE; ApartmentTable ptr = db; if (isKeyExists("s", cmd.kwargs)) { // ASC - low to high ptr = sortTable(db, FALSE); isAllocated = TRUE; } else if (isKeyExists("sr", cmd.kwargs)) { // DESC - high to low ptr = sortTable(db, TRUE); isAllocated = TRUE; } for (int i = 0; i < db.size; i++) { Apartment tmp = ptr.arr[i]; time_t d1, d2; char *pt; // if apartment not match the filter, we continue to the next pt = getValueByKey("MaxPrice", cmd.kwargs); int price = (int) (pt ? atoi(pt) : NULL); if (price && tmp.price > price) continue; pt = getValueByKey("MinNumRooms", cmd.kwargs); int rooms = (int) (pt ? atoi(pt) : NULL); if (rooms && tmp.rooms < rooms) continue; pt = getValueByKey("MaxNumRooms", cmd.kwargs); rooms = (int) (pt ? atoi(pt) : NULL); if (rooms && tmp.rooms > rooms) continue; // return all apartments that was inserted @dayBack ago pt = getValueByKey("Enter", cmd.kwargs); int dayBack = (int) (pt ? atoi(pt) : NULL); if (dayBack > 0) { struct tm entryDate; int now = (int) time(NULL); now = now - (84600 * dayBack); entryDate.tm_hour = 23; entryDate.tm_min = 59; entryDate.tm_sec = 59; entryDate.tm_year = tmp.entry_year + 100; entryDate.tm_mon = tmp.entry_month - 1; entryDate.tm_mday = tmp.entry_day; d1 = mktime(&entryDate); if (now - d1 > 0) continue; } char* date = getValueByKey("Date", cmd.kwargs); if (date != NULL) { struct tm endDate; struct tm startDate; endDate.tm_hour = 23; endDate.tm_min = 59; endDate.tm_sec = 59; endDate.tm_year = atoi(substring(date, 5 , 4)) - 1900; endDate.tm_mon = atoi(substring(date, 3 , 2)) - 1; endDate.tm_mday = atoi(substring(date, 1 , 2)); startDate.tm_hour = 23; startDate.tm_min = 59; startDate.tm_sec = 59; startDate.tm_year = tmp.entry_year + 100; startDate.tm_mon = tmp.entry_month - 1; startDate.tm_mday = tmp.entry_day; d1 = mktime(&endDate); d2 = mktime(&startDate); if (d2 - d1 > 0) continue; } printApartment(tmp); } if (isAllocated == TRUE) { // free the memory that allocated if the array is sorted //free(ptr.arr); } }