Last active
August 29, 2015 14:02
-
-
Save Fiona-J-W/99c8be5461873904db6e to your computer and use it in GitHub Desktop.
inversion-calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <string> | |
#include <iostream> | |
#include <iterator> | |
#include <cstdint> | |
int main() { | |
std::string line; | |
while(std::getline(std::cin, line)) { | |
std::size_t inversions = 0; | |
auto begin = line.begin(); | |
auto end = line.end(); | |
for (auto it = begin; it != end; ++it) { | |
inversions += std::count_if(begin, it, [&](auto val){return val > *it;}); | |
} | |
std::cout << "inversions in '" << line << "': " << inversions << '\n'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile for a.out | |
# created with makefile-creator | |
#################### | |
#Settings: | |
CXX ?= g++ | |
FLAGS += -Wall -Wextra -Wpedantic -std=c++1y -O3 -mtune=native -Werror -DNDEBUG | |
LIBS += | |
INCLUDES += | |
TARGET = a.out | |
OBJECTS = main.o | |
#################### | |
#Rules: | |
$(TARGET) : $(OBJECTS) | |
$(CXX) $(FLAGS) -o $(TARGET) $(OBJECTS) $(LIBS) | |
%.o: | |
$(CXX) $(FLAGS) $(INCLUDES) -c -o $@ $< | |
clean: | |
rm *.o | |
all: $(TARGET) | |
#################### | |
#Dependencies: | |
main.o: main.cpp makefile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use=cpp | |
use=release |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment