go to start Sol W9
|home |print view |recent changes |changed November 16, 2018 |
exact
|You are 18.205.19.203 <- set your identity!

Sections: 1. Wcount | 2. Wdiffcount | 3. wfavorite | 4. wlist | 5. primes | readln |

1. Wcount ^

int wcount(istream& in) {
	istream_iterator<Word> start{in};
	istream_iterator<Word> end{};
	return distance(start, end);
}

2. Wdiffcount ^


3. wfavorite ^


4. wlist ^

struct Comparator {
	bool operator()(Word w1, Word w2) const {

		if (w1.toString().length() == w2.toString().length()) {
			return w1 < w2;
		} else {
			return w1.toString().length() < w2.toString().length();
		}

	};
};

//für das reverste Sortieren würden wir einfach return w1 > w2 schreiben

void wlist5(std::istream& in, std::ostream& out) {
	Word w{};
	std::set<Word, Comparator> words{};

	std::istream_iterator<Word> inIt{in};
	std::istream_iterator<Word> inEof{};
	std::copy(inIt, inEof, inserter(words, begin(words)));

	std::ostream_iterator<Word> outIt{out, ", "};
	std::copy(words.begin(), words.end(), outIt);
}

5. primes ^


readln ^

//Base Case
std::istream& readln(std::istream& in) {
	return in;
}


template <typename First, typename... Rest>
std::istream& readln(std::istream& in, First& first, Rest&... rest) {

	//get just one line
	std::string s{};
	getline(in,s);
	std::istringstream i2{s};

	//Read Element
	i2 >> first;

	//if argument didnt match, stream is in failstate
	if (i2.fail()) {
		i2.clear();
		i2.ignore();
		readln(i2, first, rest...);
	}

	//if reading was fine, continue with remaining args
	else {
		//Note: if check is not necessary, just for reference
		if (sizeof...(Rest)) {
			readln(i2, rest...);
		}
	}

	return in;
}


|home |print view |recent changes |changed November 16, 2018 |
exact
|You are 18.205.19.203 <- set your identity!

Sol W9
go to start