Added code
This commit is contained in:
commit
b2f43c1584
58
main.cpp
Normal file
58
main.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void usage (const char *name)
|
||||
{
|
||||
cout << "Usage: " << name << " [max input] [max output] [factor]" << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
vector<string> args(&(argv[1]), &(argv[argc]));
|
||||
double gamma = 2.2;
|
||||
int max_in = 255;
|
||||
int max_out = 255;
|
||||
int line_size = 80;
|
||||
int line_count;
|
||||
int count;
|
||||
double val;
|
||||
int output;
|
||||
|
||||
if (args.size() < 3)
|
||||
{
|
||||
usage(argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
max_in = stoi(args[0]);
|
||||
max_out = stoi(args[1]);
|
||||
gamma = stod(args[2]);
|
||||
|
||||
count = to_string(max_out).size();
|
||||
line_count = line_size / (count + 2);
|
||||
line_count -= line_count % 8;
|
||||
for (int i = 0; i <= max_in; ++i)
|
||||
{
|
||||
val = i;
|
||||
val /= max_in;
|
||||
val = pow(val, gamma);
|
||||
val *= max_out;
|
||||
val += 0.5;
|
||||
output = val;
|
||||
|
||||
printf("%*d, ", count, output);
|
||||
|
||||
if ((i + 1) % line_count == 0)
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user