示例#1
0
int check_shortname()
{
	int i;
	for (i = 0; i < 3; i++)
		if (!capital(shortName[i]) || shortName[i]==0)
			return 1;
	return 0;
}
示例#2
0
文件: caesar1.c 项目: dudren/CS50
//changes alphabetical char from alpha to ascii number
char toAscii(char alphaChar)
{
    int asciiChar = alphaChar;
    if(capital(alphaChar) == 1)
        asciiChar += 65;
    if(lowerCase(alphaChar) == 1)
        asciiChar += 97;
    return asciiChar;
}
示例#3
0
文件: caesar1.c 项目: dudren/CS50
//changes alphabetical char from ascii to alpha number
char toAlpha(char asciiChar)
{
    int alphaNum = asciiChar;
    if(capital(asciiChar) == 1)
        alphaNum -= 65;
    if(lowerCase(asciiChar) == 1)
        alphaNum -= 97;
    return alphaNum;
}
示例#4
0
char *cap_strnzcpy(char *s1, char *s2, int n)
   {
   char *temp = s1;
   int i;

   for (i = 0; i < n; i++)
      {
      if (lower_p(*s2))
         *s1++ = capital(*s2++);
      else
         *s1++ = *s2++;
      }
   *s1 = '\0';
   return (temp);
   }
示例#5
0
int main(void)
{
    //asks user for name and stores in string
    printf("What is your name?\n");
    char* name = GetString();
    
    //loops through each letter in the string
    for (int i = 0, n = strlen(name); i < n; i++)
    {
        char initial;
        //if the char is a space, go to next letter and print in uppercase
        if (space(name[i]) == 1 && (capital(name[i + 1]) == 1 || lowerCase(name[i + 1]) == 1))
        {
            initial = name[i + 1];
            printf("%c", toupper(initial));
        }
    }
    printf("\n");
}
示例#6
0
文件: caesar1.c 项目: dudren/CS50
int main(int argc, char* argv[])
{
    //stops the program if there are no command line arguments
    if (argc != 2)
    {
        printf("You must enter an argument.\n");
        return 1;
    }
    
    else
    {
        //key is changed to integer
        int k = atoi(argv[1]);
        printf("Enter a string you would like to encrypt with Caesar's cipher: \n");
        //gets the string from the user that we would like to encrypt
        char* s = GetString();
        char cipheredNum;
        int result;
        
        //loops through each char of the string
        for (int i = 0, n = strlen(s); i < n; i++)
        {
            //if the char is a capital or lowercase letter
            if (capital(s[i]) == 1 || lowerCase(s[i]) == 1)
            {
                //change to alphanumeric value, run the cipher, then change back to ascii
                int alphaNum = toAlpha(s[i]);
                cipheredNum = cipher(alphaNum, k);
                result = toAscii(cipheredNum);
            }
            //if the char is neither capital or lowercase, it stays the same
            else
                result = s[i];
            //prints the ciphered char before moving on to next char
            printf("%c", result);
        }
        printf("\n");
        return 0;
    }
}
示例#7
0
int main(void)
{

int i, len;
char slogan[MAXLEN];

/***** puts entered slogan into a string *****/

printf("> Enter a slogan:  ");
scanf("%s", slogan);
printf("\n\n");

/***** gives length of string *****/

len = strlen(slogan);

/***** prints first part of cheer *****/

i=0;

while (i<len) {
	printf("Give me a ... %c\n", slogan[i]);
	i++;
}

printf("\n\n");

/***** Makes all letter capital *****/

capital(len, slogan);

/***** prints second part of cheer *****/

printf("What does that spell?! %s!\n\n", slogan); 

return (0);

}
void AssetAllocationModel::BuildCplexModel(IloEnv &env, IloModel &model, IloExpr &objective, unsigned int stage, const double *prev_decisions, const double *scenario, vector<IloNumVar> &decision_vars, vector<IloRange> &dual_constraints) const {
	//assets count N
	unsigned int assets = GetAssetsCount();
	bool root_node = (stage == 1);
	bool last_stage = (stage == GetStagesCount());
	double conf_inv = 1 - param_.confidence;
	double conf_inv_other = 1 - param_.confidence_other;

	IloNumVarArray x(env, assets);
	for (unsigned int i = 0; i < assets; ++i) {
		//zero lower bound
		x[i] = IloNumVar(env, 0.0);

		//max profit = min negative loss
		if (!root_node) {
			switch (param_.risk_measure) {
			case RISK_CVAR_NESTED:
				objective += -1 * x[i];
				break;
			case RISK_CVAR_MULTIPERIOD:
				objective += -1 * param_.expectation_coefficients[stage - 1] * x[i];
				break;
			}
		}

		decision_vars.push_back(x[i]);
	}
	model.add(x);

	//var c = positive value in the cvar
	IloNumVar c(env, 0.0);
	if (!root_node && (param_.risk_measure == RISK_CVAR_MULTIPERIOD)) {
		//objective with risk aversion coef lambda
		objective += param_.risk_coefficients[stage - 1] / conf_inv * c;
		model.add(c);
	}

	//var c_other = positive value in the cvar
	IloNumVar c_other(env, 0.0);
	if (!root_node && (param_.risk_measure == RISK_CVAR_MULTIPERIOD)) {
		//objective with risk aversion coef lambda
		objective += param_.risk_coefficients_other[stage - 1] / conf_inv_other * c_other;
		model.add(c_other);
	}

	//var var = variable to calculate CVaR = VaR level
	IloNumVar var(env, GetRecourseLowerBound(stage), GetRecourseUpperBound(stage));
	//objective according to the risk aversion lambda
	if (!last_stage) {
		//last stage has no recourse
		objective += param_.risk_coefficients[stage] * var;
	}
	model.add(var);
	decision_vars.push_back(var);

	//var var_other = variable to calculate CVaR = VaR level
	IloNumVar var_other(env, GetRecourseLowerBound(stage), GetRecourseUpperBound(stage));
	//objective according to the risk aversion lambda
	if (!last_stage) {
		//last stage has no recourse
		objective += param_.risk_coefficients_other[stage] * var_other;
	}
	model.add(var_other);
	decision_vars.push_back(var_other);

	//transaction costs dummy variable
	IloNumVarArray trans(env, assets);
	for (unsigned int i = 0; i < assets; ++i) {
		//zero lower bound
		trans[i] = IloNumVar(env, 0.0);
	}
	if (!root_node) {
		model.add(trans);
	}

	//constraint capital = sum of the weights equals initial capital one
	IloExpr cap_expr(env);
	double transaction_coef = param_.transaction_costs;
	for (unsigned int i = 0; i < assets; ++i) {
		cap_expr += x[i];
		if (!root_node) {
			cap_expr += transaction_coef * trans[i];
		}
	}
	double total_capital;
	if (root_node) {
		//no parent, init the capital with 1
		total_capital = 1.0;
	}
	else {
		//sum up the capital under this scenario
		total_capital = CalculateCapital(prev_decisions, scenario);
	}
	IloRange capital(env, total_capital, cap_expr, total_capital);
	model.add(capital);
	dual_constraints.push_back(capital);

	//constraint transaction costs
	IloRangeArray costs_pos(env);
	IloRangeArray costs_neg(env);
	if (!root_node) {
		for (unsigned int i = 0; i < assets; ++i) {
			//current position in asset i
			double parent_value = scenario[i] * prev_decisions[i]; //decisions and scenarios have the same order here, decisions start with allocations

			//positive and negative part of linearization for absolute value
			IloExpr cost_expr_pos(env);
			IloExpr cost_expr_neg(env);
			cost_expr_pos += x[i];
			cost_expr_pos += -1 * trans[i];
			cost_expr_neg += -1 * x[i];
			cost_expr_neg += -1 * trans[i];
			costs_pos.add(IloRange(env, cost_expr_pos, parent_value));
			costs_neg.add(IloRange(env, cost_expr_neg, -parent_value));

			dual_constraints.push_back(costs_pos[i]);
			dual_constraints.push_back(costs_neg[i]);
		}
		model.add(costs_pos);
		model.add(costs_neg);
	}

	//contraint the positive part "c" of the CVaR value
	IloExpr cvar_expr(env);
	IloRange cvar;
	if (!root_node && (param_.risk_measure == RISK_CVAR_MULTIPERIOD)) {
		cvar_expr += c; //the varible itself
		for (unsigned int i = 0; i < assets; ++i) {
			cvar_expr += x[i]; //-c transp x
		}
		double parent_var = prev_decisions[assets]; //var is right after the allocations in decision vector
		cvar = IloRange(env, -parent_var, cvar_expr); //previous value at risk
		model.add(cvar);
		dual_constraints.push_back(cvar);
	}

	//contraint the positive part "c_other" of the CVaR value
	IloExpr cvar_expr_other(env);
	IloRange cvar_other;
	if (!root_node && (param_.risk_measure == RISK_CVAR_MULTIPERIOD)) {
		cvar_expr_other += c_other; //the varible itself
		for (unsigned int i = 0; i < assets; ++i) {
			cvar_expr_other += x[i]; //-c transp x
		}
		double parent_var_other = prev_decisions[assets + 1]; //var_other is right after var in the decisions vector
		cvar_other = IloRange(env, -parent_var_other, cvar_expr_other); //previous value at risk
		model.add(cvar_other);
		dual_constraints.push_back(cvar_other);
	}

}