repo_name
stringlengths 6
97
| path
stringlengths 3
341
| text
stringlengths 8
1.02M
|
---|---|---|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/config_type.h | <filename>baselines/1_CCGrid15/include/cowic/config_type.h
//config_type.h
#ifndef _CONFIG_TYPE_H_
#define _CONFIG_TYPE_H_
template <typename EnumType>
struct EnumName
{
static const char* List[];
};
enum class ModelType{
WordDict,
PhraseDict,
ColumnWised
};
template <>
const char* EnumName<ModelType>::List[];
enum class DictEncoderType{
Huffman,
Canonical
};
template <>
const char* EnumName<DictEncoderType>::List[];
enum class FreshEncoderType{
Plain,
Auxiliary
};
template <>
const char* EnumName<FreshEncoderType>::List[];
enum class NumberEncoderType{
Unary,
Gamma,
Delta
};
template <>
const char* EnumName<NumberEncoderType>::List[];
enum class ColumnModelType{
WordDict,
PhraseDict,
Timestamp,
IP,
Number,
FixPrecisionNumber
};
template <>
const char* EnumName<ColumnModelType>::List[];
enum class DictColumnModelType{
WordDict,
PhraseDict,
};
template <>
const char* EnumName<DictColumnModelType>::List[];
enum class SpecifyColumnModelType{
Timestamp,
IP,
Number,
FixPrecisionNumber
};
template <>
const char* EnumName<SpecifyColumnModelType>::List[];
template<typename EnumType>
EnumType ConvertStringToEnum(const char* pStr);
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/number_encoder.h | //number_encoder.h
#ifndef _NUMBER_ENCODER_H_
#define _NUMBER_ENCODER_H_
#include "encoder.h"
class NumberEncoder : public Encoder{
public:
void buildCoder(const unordered_map<string, int>& wordFreqDict);
bool isFresh(const string& word) const;
/** @word is in fact an positive integer.
*/
BitArray encode(const string& word) const;
int decode(BinaryCode& code, string& word) const;
void parse(string& dumpStr);
string dump() const;
/* Two function do the real work. encode & decode integer.
* */
virtual BitArray encode(unsigned int num) const = 0;
virtual int decode(BinaryCode& code, unsigned int& num) const = 0;
private:
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/number.h | //number.h
#ifndef _NUMBER_H_
#define _NUMBER_H_
#include <regex.h>
#include "abstract_number.h"
class Number : public AbstractNumber{
public:
Number(unsigned int numericVal, const string& beforeVal, const string& afterVal);
bool isIllegal() const;
static Number parse(const string& ipStr);
static const Number illegal;
private:
static void initRegex();
static bool regex_initialized;
static regex_t decimal_regex;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/src/encoder/canonical_huffman_encoder.h | /* Cowic is a C++ library to compress formatted log like Apache access log.
*
* Cowic is released under the New BSD license (see LICENSE.txt). Go to the
* project home page for more info:
*
* https://github.com/linhao1990/cowic.git
*/
//canonical_huffman_encoder.h
#ifndef _CANONICAL_HUFFMAN_ENCODER_H_
#define _CANONICAL_HUFFMAN_ENCODER_H_
#include "huffman_encoder.h"
#include <memory>
using std::shared_ptr;
class CanonicalHuffmanEncoder : public Encoder{
public:
CanonicalHuffmanEncoder();
void buildCoder(const unordered_map<string, int>& wordFreqDict);
bool isFresh(const string& word) const;
BitArray encode(const string& word) const;
int decode(BinaryCode& code, string& word) const;
void parse(string& dumpStr);
string dump() const;
~CanonicalHuffmanEncoder();
private:
vector<SymbolLen> symbolLenVec;
int maxLength;
vector<int> numl;
vector<int> numBeforeLength;
vector<int> firstcode;
unordered_map<string, BitArray> word2CodeDict;
shared_ptr<HuffmanEncoder> encoderPtr;
// The SymbolLenVec is calculated and sorted, calculate code for each symbol
void buildCanonicalCoder();
void calculateMaxLength();
void countNuml();
void calculateSymbolCode();
void calculateFirstcode();
int calculateOffset(int length, int v) const;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/src/encoder/bit_array.h | /* Cowic is a C++ library to compress formatted log like Apache access log.
*
* Cowic is released under the New BSD license (see LICENSE.txt). Go to the
* project home page for more info:
*
* https://github.com/linhao1990/cowic.git
*/
//bit_array.h
#ifndef _BIT_ARRAY_H
#define _BIT_ARRAY_H
#include <vector>
#include <string>
#include <iostream>
using std::vector;
using std::string;
using std::cout;
using std::endl;
class BitArray{
public:
BitArray();
/** All bits in binaryCode is valid. Push back each bit in the string.
*/
BitArray(const string& binaryCode);
/* Only the first bitNum bits in the string is valid. The remaining bits will be ignored.
*/
BitArray(const string& binaryCode, unsigned int bitNum);
BitArray(unsigned char c);
BitArray(unsigned int num);
BitArray(const BitArray& rhs);
BitArray(BitArray&& rhs);
BitArray& operator=(const BitArray& rhs);
BitArray& operator=(BitArray&& rhs);
void push_back(bool b);
size_t size() const;
bool get(int index) const;
bool operator[](int index) const;
/** transform the bits into binary string. organize 8 bits into a char.
* padding 0 if there are not enough bits.
*/
string to_binary_str() const;
/** transform the bits into plain str, each bit is represent by a char '0' or '1'.
*/
string to_plain_str() const;
void erase(int start, int length);
/* The user shall gurantee that size() > 0, otherwise it will causes undefined behaviour.
* */
bool topWithPop();
BitArray& operator +=(const BitArray& otherCode);
static BitArray parseFrom(const string& plainStr);
private:
vector<bool> mArray;
void appendBitsInChar(unsigned char c, unsigned int validBitNum = 8);
void appendBitsInStr(const string& binaryCode, unsigned int bitNum);
};
const BitArray operator+(const BitArray& code1, const BitArray& code2);
// used in unary code
BitArray getBinaryWithoutHighestOne(unsigned int num);
BitArray getRightmostBits(unsigned int num, unsigned int bitNum);
//A wrapper of BitArray with pos point to the locaction has been decoded.
//So we do not need to modify code while decode.
class BinaryCode{
public:
BinaryCode(BitArray&& codeVal) : code(std::move(codeVal)), codeLen(code.size()), pos(0){}
inline bool finish() const{
return remainSize() == 0;
}
inline bool getFirstBitMoveToNext(){
return code[pos++];
}
inline size_t remainSize() const{
return codeLen - pos;
}
const BitArray code;
const size_t codeLen;
int pos;
};
unsigned char decodeChar(BinaryCode& code);
int decodeChar(BinaryCode& code, unsigned char& c);
unsigned int decodeInt(BinaryCode& code);
int decodeInt(BinaryCode& code, unsigned int& num);
int decodePlainStr(BinaryCode& code, string& word, unsigned int length);
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/compressor_config.h | <gh_stars>1-10
//compressor_config.h
#ifndef _COMPRESSOR_CONFIG_H_
#define _COMPRESSOR_CONFIG_H_
#include <string>
#include <vector>
#include <memory>
#include "config_type.h"
using std::string;
using std::vector;
using std::shared_ptr;
class SpecifyConfig{
public:
SpecifyConfig(int columnVal, SpecifyColumnModelType modelTypeVal, const string& argVal);
int getColumn() const;
SpecifyColumnModelType getModelType() const;
string getArg() const;
static SpecifyConfig parse(const string& str);
private:
int column;
SpecifyColumnModelType modelType;
string arg;
};
typedef struct{
ModelType modelType;
DictEncoderType dictEncoderType;
FreshEncoderType freshEncoderType;
NumberEncoderType numberEncoderType;
DictColumnModelType dictColumnModelType;
vector<SpecifyConfig> specifyConfigs;
} CompressorConfiguration;
class CompressorConfigSingleton{
public:
static shared_ptr<CompressorConfigSingleton> getInstance();
/* @return value corresponding this key. '' if key is not found.
* */
ModelType getModelType();
DictEncoderType getDictEncoderType();
FreshEncoderType getFreshEncoderType();
NumberEncoderType getNumberEncoderType();
DictColumnModelType getDictColumnModelType();
SpecifyConfig* getSpecifyConfig(int column);
private:
CompressorConfigSingleton();
static shared_ptr<CompressorConfigSingleton> mInstance;
static const string filename;
static CompressorConfiguration config;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/src/encoder/encoder.h | <gh_stars>1-10
/* Cowic is a C++ library to compress formatted log like Apache access log.
*
* Cowic is released under the New BSD license (see LICENSE.txt). Go to the
* project home page for more info:
*
* https://github.com/linhao1990/cowic.git
*/
//encoder.h
#ifndef _ENCODER_H
#define _ENCODER_H
#include <unordered_map>
#include "bit_array.h"
using std::unordered_map;
class Encoder{
public:
Encoder();
virtual void buildCoder(const unordered_map<string, int>& wordFreqDict) = 0;
virtual bool isFresh(const string& word) const = 0;
virtual BitArray encode(const string& word) const = 0;
/** consume @code and store the first word in @word
* @return 0 on success, -1 means no word can be decoded until reach end of code
*/
virtual int decode(BinaryCode& code, string& word) const = 0;
virtual void parse(string& dumpStr) = 0;
virtual string dump() const = 0;
virtual ~Encoder();
private:
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/timestamp_model.h | //timestamp_model.h
#ifndef _TIMESTAMP_MODEL_H_
#define _TIMESTAMP_MODEL_H_
#include <memory>
#include "model.h"
#include "dictionary_model.h"
using std::shared_ptr;
class TimestampModel : public Model{
public:
TimestampModel();
TimestampModel(const shared_ptr<DictionaryModel>& dictModelPtrVal, const string& formatVal);
void updateColumn(const string& columnStr, int column);
/* <MODEL_NAME>
* <#MODEL_BYTE_LEN>
* <MODEL_DUMP_STR>
* */
string dump() const;
void parse(string& dumpStr);
BitArray compressMayEmptyWord(const string& word);
BitArray compressMayEmptyColumn(const string& word, int column);
int decompressMayEmptyWord(BinaryCode& code, string& word) const;
int decompressMayEmptyColumn(BinaryCode& code, string& word, int column) const;
BitArray compressColumn(const string& columnStr, int column);
int decompressColumn(BinaryCode& code, string& columnStr, int column) const;
string getModelName() const;
private:
/* The model used to process string when the timestamp cannot be parsed successfully.
*/
shared_ptr<DictionaryModel> dictModelPtr;
string format;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/src/model/model.h | /* Cowic is a C++ library to compress formatted log like Apache access log.
*
* Cowic is released under the New BSD license (see LICENSE.txt). Go to the
* project home page for more info:
*
* https://github.com/linhao1990/cowic.git
*/
//model.h
#ifndef _MODEL_H
#define _MODEL_H
#include <iostream>
#include <string>
#include "bit_array.h"
using std::string;
using std::cout;
using std::endl;
class Model{
public:
Model();
virtual void updateColumn(const string& columnStr, int column) = 0;
virtual string dump() const = 0;
virtual void parse(string& dumpStr) = 0;
/** Return compressed form of word.
* Side effect: will update model for future.
*/
virtual BitArray compressColumn(const string& columnStr, int column) = 0;
virtual int decompressColumn(BinaryCode& code, string& columnStr, int column) const = 0;
virtual string getModelName() const = 0 ;
virtual ~Model();
private:
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/timestamp.h | //timestamp.h
#ifndef _TIMESTAMP_H_
#define _TIMESTAMP_H_
#include "time.h"
#include <string>
#include <stdlib.h>
#include <regex.h>
using std::string;
class Timestamp{
public:
Timestamp(time_t timestampValue, const string& timezoneValue);
Timestamp(time_t timestampValue, const string& timezoneValue, const string& afterVal);
time_t getNumericalTime() const;
const string& getTimezone() const;
const string& getAfter() const;
string to_plain_str(const string& format) const;
static Timestamp parse(const string& time_str, const string& format);
bool operator ==(const Timestamp& other) const;
bool operator !=(const Timestamp& other) const;
static const Timestamp illegal;
private:
time_t timestamp;
string timezone;
string after;
/* @return timezone string. "" if do not find a legal timezone
* */
static string extractTimezone(const string& time_str, const string& format);
static string translate2Env(const string& timezone);
static void initRegex();
static bool regex_initialized;
static regex_t num_tz_regex;
static regex_t gmt_tz_regex;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/variable_byte_encoder.h | //variable_byte_encoder.h
#ifndef _VARIABLE_BYTE_ENCODER_H_
#define _VARIABLE_BYTE_ENCODER_H_
#include "number_encoder.h"
/* Variable byte (VB) encoding uses an integral number of bytes to encode a gap.
* The last 7 bits of a byte are ``payload'' and encode part of the gap.
* The first bit of the byte is a continuation bit . It is set to 1 for the last byte
* of the encoded gap and to 0 otherwise.
* */
class VariableByteEncoder : public NumberEncoder{
public:
BitArray encode(unsigned int num) const;
int decode(BinaryCode& code, unsigned int& num) const;
private:
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/abstract_number.h | <reponame>JinYang88/LogZip
//abstract_number.h
#ifndef _ABSTRACT_NUMBER_H_
#define _ABSTRACT_NUMBER_H_
#include <string>
using std::string;
class AbstractNumber{
public:
AbstractNumber(unsigned int numericVal, const string& beforeVal, const string& afterVal);
unsigned int getNumeric() const;
string getBefore() const;
string getAfter() const;
bool operator ==(const AbstractNumber& other) const;
bool operator !=(const AbstractNumber& other) const;
virtual string to_plain_str() const;
virtual bool isIllegal() const = 0;
private:
unsigned int numeric;
string before;
string after;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/src/encoder/auxiliary_encoder.h | /* Cowic is a C++ library to compress formatted log like Apache access log.
*
* Cowic is released under the New BSD license (see LICENSE.txt). Go to the
* project home page for more info:
*
* https://github.com/linhao1990/cowic.git
*/
//auxiliary_encoder.h
#ifndef _AUXILIARY_ENCODER_H_
#define _AUXILIARY_ENCODER_H_
#include "fresh_encoder.h"
#include "plain_encoder.h"
#include "word_list_encoder.h"
class AuxiliaryEncoder : public FreshEncoder{
public:
bool isFresh(const string& word) const;
void updateWord(const string& word);
void setFreshCode(const BitArray& freshCodeValue, const BitArray& auxiliaryCodeValue);
BitArray encode(const string& word) const;
int decode(BinaryCode& code, string& word) const;
void parse(string& dumpStr);
/* Format:
* <#AUXILIARY_ENCODER_BYTE_LEN>
* <AUXILIARY_ENCODER_DUMP_STR>
* */
string dump() const;
int decodeFresh(BinaryCode& code, string& word, bool isAuxiliary) const;
private:
BitArray auxiliaryCode;
shared_ptr<WordListEncoder> wordlistEncoderPtr;
shared_ptr<PlainEncoder> plainEncoderPtr;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/src/model/fix_precision_number_model.h | <gh_stars>1-10
/* Cowic is a C++ library to compress formatted log like Apache access log.
*
* Cowic is released under the New BSD license (see LICENSE.txt). Go to the
* project home page for more info:
*
* https://github.com/linhao1990/cowic.git
*/
//fix_precision_number_model.h
#ifndef _FIX_PRECISION_NUMBER_MODEL_H_
#define _FIX_PRECISION_NUMBER_MODEL_H_
#include "abstract_number_model.h"
#include "number_encoder.h"
class FixPrecisionNumberModel : public AbstractNumberModel<unsigned int>{
public:
FixPrecisionNumberModel();
FixPrecisionNumberModel(const shared_ptr<DictionaryModel>& dictModelPtrVal, unsigned int precisionVal);
string dump() const;
void parse(string& dumpStr);
BitArray compressNumber(unsigned int num);
int decompressNumber(BinaryCode& code, unsigned int& num) const;
shared_ptr<AbstractNumber<unsigned int> > parseColumnStr(const string& columnStr);
string toPlainStr(unsigned int num, const string& before, const string& after) const;
string getModelName() const;
private:
unsigned int precision;
shared_ptr<NumberEncoder> numberEncoderPtr;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/src/model/ip_model.h | <filename>baselines/1_CCGrid15/src/model/ip_model.h
/* Cowic is a C++ library to compress formatted log like Apache access log.
*
* Cowic is released under the New BSD license (see LICENSE.txt). Go to the
* project home page for more info:
*
* https://github.com/linhao1990/cowic.git
*/
//ip_model.h
#ifndef _IP_MODEL_H_
#define _IP_MODEL_H_
#include "abstract_number_model.h"
class IPModel : public AbstractNumberModel<unsigned int>{
public:
IPModel();
IPModel(const shared_ptr<DictionaryModel>& dictModelPtrVal);
shared_ptr<AbstractNumber<unsigned int> > parseColumnStr(const string& columnStr);
string toPlainStr(unsigned int num, const string& before, const string& after) const;
string getModelName() const;
private:
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/src/encoder/word_list_encoder.h | <reponame>JinYang88/LogZip<gh_stars>1-10
/* Cowic is a C++ library to compress formatted log like Apache access log.
*
* Cowic is released under the New BSD license (see LICENSE.txt). Go to the
* project home page for more info:
*
* https://github.com/linhao1990/cowic.git
*/
//word_list_encoder.h
#ifndef _WORD_LIST_ENCODER_H_
#define _WORD_LIST_ENCODER_H_
#include <memory>
#include "number_encoder.h"
using std::shared_ptr;
class WordListEncoder : public Encoder{
public:
WordListEncoder(const string& wordsFilenameValue);
void buildCoder(const unordered_map<string, int>& wordFreqDict);
bool isFresh(const string& word) const;
/* The caller must gurantee word exists! */
BitArray encode(const string& word) const;
/* The caller must gurantee code can be decoded by word list.*/
int decode(BinaryCode& code, string& word) const;
void parse(string& dumpStr);
string dump() const;
void append(const string& word);
bool updateThenCheckExist(const string& word);
private:
// for decompress. give an index, find corresponding word
vector<string> wordList;
// for compress. give an word, find its index.
// decrease search word time from O(N) to O(1)
unordered_map<string, BitArray> word2CodeDict;
// during compress step, when meeting a fresh word, decide whether to
// store it in auxiliary word list. Store the word as a part of model.
string wordsFilename;
// encode number.
shared_ptr<NumberEncoder> numberEncoderPtr;
// record frequency of fresh word, move it to word list if frequency
// is larger than a threshold.
unordered_map<string, int> freshWord2FreqDict;
string dumpWordList2File(const string& wordsDumpStr) const;
void append2File(const string& word);
void append2WordList(const string& word);
/* Parse word list*/
void parseWordList(const string& wordListStr);
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/fix_precision_number_model.h | //fix_precision_number_model.h
#ifndef _FIX_PRECISION_NUMBER_MODEL_H_
#define _FIX_PRECISION_NUMBER_MODEL_H_
#include "abstract_number_model.h"
#include "number_encoder.h"
class FixPrecisionNumberModel : public AbstractNumberModel{
public:
FixPrecisionNumberModel();
FixPrecisionNumberModel(const shared_ptr<DictionaryModel>& dictModelPtrVal, unsigned int precisionVal);
string dump() const;
void parse(string& dumpStr);
BitArray compressNumber(unsigned int num);
int decompressNumber(BinaryCode& code, unsigned int& num) const;
shared_ptr<AbstractNumber> parseColumnStr(const string& columnStr);
string toPlainStr(unsigned int num, const string& before, const string& after) const;
string getModelName() const;
private:
unsigned int precision;
shared_ptr<NumberEncoder> numberEncoderPtr;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/src/encoder/fresh_encoder.h | /* Cowic is a C++ library to compress formatted log like Apache access log.
*
* Cowic is released under the New BSD license (see LICENSE.txt). Go to the
* project home page for more info:
*
* https://github.com/linhao1990/cowic.git
*/
//fresh_encoder.h
#ifndef _FRESH_ENCODER_H_
#define _FRESH_ENCODER_H_
#include "encoder.h"
class FreshEncoder : public Encoder{
public:
void buildCoder(const unordered_map<string, int>& wordFreqDict);
BitArray getFreshCode() const;
virtual void updateWord(const string& word){}
virtual void setFreshCode(const BitArray& freshCodeValue, const BitArray& auxiliaryCodeValue);
virtual int decodeFresh(BinaryCode& code, string& word, bool isAuxiliary = false) const = 0;
private:
BitArray freshCode;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/model.h | //model.h
#ifndef _MODEL_H
#define _MODEL_H
#include <iostream>
#include <string>
#include "bit_array.h"
using std::string;
using std::cout;
using std::endl;
class Model{
public:
Model();
virtual void updateColumn(const string& columnStr, int column) = 0;
virtual string dump() const = 0;
virtual void parse(string& dumpStr) = 0;
/** Return compressed form of word.
* Side effect: will update model for future.
*/
virtual BitArray compressColumn(const string& columnStr, int column) = 0;
virtual int decompressColumn(BinaryCode& code, string& columnStr, int column) const = 0;
virtual string getModelName() const = 0 ;
virtual ~Model();
private:
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/src/encoder/tree_node.h | /* Cowic is a C++ library to compress formatted log like Apache access log.
*
* Cowic is released under the New BSD license (see LICENSE.txt). Go to the
* project home page for more info:
*
* https://github.com/linhao1990/cowic.git
*/
//tree_node.h
#ifndef _TREE_NODE_H_
#define _TREE_NODE_H_
#include <memory>
#include "bit_array.h"
class TreeNode;
typedef std::shared_ptr<TreeNode> TreeNodePtr;
class TreeNode{
public:
TreeNode(string wordValue, int freqValue);
TreeNode(TreeNodePtr leftValue, TreeNodePtr rightValue);
int getFreq() const;
TreeNodePtr getLeft() const;
TreeNodePtr getRight() const;
string getWord() const;
BitArray getCode() const;
void setCode(const string& plainStr);
~TreeNode();
private:
TreeNodePtr left;
TreeNodePtr right;
string word;
int freq;
BitArray code;
};
#endif
|
JinYang88/LogZip | baselines/1_CCGrid15/include/cowic/dictionary_model.h | <reponame>JinYang88/LogZip
//dictionary_model.h
#ifndef _DICTIONARY_MODEL_H
#define _DICTIONARY_MODEL_H
#include <memory>
#include "model.h"
#include "encoder.h"
#include "fresh_encoder.h"
using std::shared_ptr;
class DictionaryModel : public Model{
public:
DictionaryModel();
void updateWord(const string& word);
/* Dump model into string.
* Format:
* <MODEL_NAME>
* <#DICT_BYTE_LEN>
* <WORD1> <#FREQ1>
* ...
* <WORDM> <#FREQM>
* <#ENCODER_BYTE_LEN>
* <ENCODER_DUMP_STR>
* <#FRESH_ENCODER_BYTE_LEN>
* <FRESH_ENCODER_DUMP_STR>
* Explanation:
* The first line is an integer denote dictionary length in bytes, the
* following #DICT_BYTE_LEN bytes are dictionary string. After the dictionary string is another
* integer denote encoder length in byte and the following #ENCODER_BYTE_LEN bytes are encoder.
* For the dictionary, each word info is stored in s seperate line,
* each line contains a word, a space and an frequncy.
* */
string dump() const;
void parse(string& dumpStr);
bool isWordInEncoder(const string& word) const;
BitArray compressWord(const string& word);
int decompressWord(BinaryCode& code, string& word) const;
int decompressColumn(BinaryCode& code, string& columnStr, int column) const;
int getFreq(const string& word) const;
protected:
unordered_map<string, int> word2FreqDict;
shared_ptr<Encoder> encoderPtr;
shared_ptr<FreshEncoder> freshEncoderPtr;
};
inline bool isLowFreqWord(int freq){
return freq <= 1;
}
#endif
|
vineyard2020/VineTalk | vine_Apps_EG/singleNode/opencl_darkGray/include/darkGrayArgs.h | #ifndef DARK_GREY_ARGS_HEADER
#define DARK_GREY_ARGS_HEADER
typedef struct {
int width; /**< Image width */
int height; /**< image height */
} darkGrayArgs;
#endif
|
vineyard2020/VineTalk | vine_Apps_EG/singleNode/opencl_darkGray/include/opencl_darkGray.h | <filename>vine_Apps_EG/singleNode/opencl_darkGray/include/opencl_darkGray.h
#ifndef OPENCL_DARKGRAY_H
#define OPENCL_DARKGRAY_H
#define CL_HPP_ENABLE_EXCEPTIONS
#define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_MINIMUM_OPENCL_VERSION 110
#define __CL_ENABLE_EXCEPTIONS
#include <CL/cl.hpp>
#ifdef RD_WG_SIZE_0_0
#define BLOCK_SIZE RD_WG_SIZE_0_0
#elif defined(RD_WG_SIZE_0)
#define BLOCK_SIZE RD_WG_SIZE_0
#elif defined(RD_WG_SIZE)
#define BLOCK_SIZE RD_WG_SIZE
#else
#define BLOCK_SIZE 16
#endif
bool opencl_darkGray(const int, const int, const unsigned char *, unsigned char *);
#endif
|
vineyard2020/VineTalk | vine_Apps_EG/mesos/examples/kernelLib/include/realtype.h | /*
* Copyright 2018 Foundation for Research and Technology - Hellas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 [1] [1]
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Links:
*
* [1] http://www.apache.org/licenses/LICENSE-2.0 [1]
*/
/**
* Copyright 1993-2015 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
#ifndef REALTYPE_H
#define REALTYPE_H
//#define DOUBLE_PRECISION
#ifndef DOUBLE_PRECISION
typedef float real;
#else
typedef double real;
#endif
#endif
|
ISISComputingGroup/CAENHVAsyn | CAENHVAsynApp/src/drvCAENHVAsyn.h | #ifndef DRV_CAEN_HV_ASYN_H
#define DRV_CAEN_HV_ASYN_H
/**
*-----------------------------------------------------------------------------
* Title : CAEN HV Asyn module
* ----------------------------------------------------------------------------
* File : drvCAENHVAsyn.h
* Author : <NAME>, <EMAIL>
* Created : 2019-07-23
* ----------------------------------------------------------------------------
* Description:
* EPICS Module for CAEN HV Power supplies
* ----------------------------------------------------------------------------
* This file is part of l2MpsAsyn. It is subject to
* the license terms in the LICENSE.txt file found in the top-level directory
* of this distribution and at:
* https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
* No part of l2MpsAsyn, including this file, may be
* copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE.txt file.
* ----------------------------------------------------------------------------
**/
#include <string>
#include <sstream>
#include <stdexcept>
#include <iomanip>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <utility>
#include <iostream>
#include <fstream>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#endif
#include <epicsTypes.h>
#include <epicsTime.h>
#include <epicsThread.h>
#include <epicsString.h>
#include <epicsTimer.h>
#include <epicsMutex.h>
#include <epicsEvent.h>
#include <iocsh.h>
#include <dbAccess.h>
#include <dbStaticLib.h>
#include "asynPortDriver.h"
#include <epicsExport.h>
#include "CAENHVWrapper.h"
#include "common.h"
#include "crate.h"
#define MAX_SIGNALS (3)
#define NUM_PARAMS (1500)
// Map used to generated binary records for system parameters of type 'PARAM_TYPE_CHSTATUS'.
// There will be a bi and or bo record for each bit status and an mbbi for all of the bits together.
// This maps contains MASK mapped to a vector containing a suffix appended to the record name, Record description, the short string for the MBBI and the alarm status of each mbbi entry.
// - This map is for Board parameters of type 'PARAM_TYPE_CHSTATUS'
typedef const std::map< int, std::vector< std::string > > statusRecordMap_t;
statusRecordMap_t recordFieldBdParamChStatus =
{
{ 0x000, std::vector<std::string>{ "", "", "Off", "NO_ALARM" } },
{ 0x001, std::vector<std::string>{ "_ON", "Ch is on", "On", "NO_ALARM" } },
{ 0x002, std::vector<std::string>{ "_RU", "Ch is ramping up", "Ramping Up", "NO_ALARM" } },
{ 0x004, std::vector<std::string>{ "_RD", "Ch is ramping down", "Ramping Down", "NO_ALARM" } },
{ 0x008, std::vector<std::string>{ "_OC", "Ch is in overcurrent", "Over-Current", "MAJOR" } },
{ 0x010, std::vector<std::string>{ "_OV", "Ch is in overvoltage", "Over-Voltage", "MAJOR" } },
{ 0x020, std::vector<std::string>{ "_UV", "Ch is in undervoltage", "Under-Voltage", "MAJOR" } },
{ 0x040, std::vector<std::string>{ "_ET", "Ch is in external trip", "External Trip", "MAJOR" } },
{ 0x080, std::vector<std::string>{ "_MV", "Ch is in max V", "Max V", "MAJOR" } },
{ 0x100, std::vector<std::string>{ "_ED", "Ch is in external disable", "Ext. Disable", "MAJOR" } },
{ 0x200, std::vector<std::string>{ "_IT", "Ch is in internal trip", "Internal Trip", "MAJOR" } },
{ 0x400, std::vector<std::string>{ "_CE", "Ch is in calibration error", "Calib. Error", "MAJOR" } },
{ 0x800, std::vector<std::string>{ "_UN", "Ch is unplugged", "Unplugged", "MAJOR" } },
};
// - This map is for Channel parameters of type 'PARAM_TYPE_CHSTATUS'
statusRecordMap_t recordFieldChParamChStatus =
{
{ 0x0000, std::vector<std::string>{"", "", "Off", "NO_ALARM"} },
{ 0x0001, std::vector<std::string>{"_ON", "Ch is on", "On", "NO_ALARM"} },
{ 0x0002, std::vector<std::string>{"_RU", "Ch is ramping up", "Ramping Up", "NO_ALARM"} },
{ 0x0004, std::vector<std::string>{"_RD", "Ch is ramping down", "Ramping Down", "NO_ALARM"} },
{ 0x0008, std::vector<std::string>{"_OC", "Ch is in overcurrent", "Over-Current", "MAJOR"} },
{ 0x0010, std::vector<std::string>{"_OV", "Ch is in overvoltage", "Over-Voltage", "MAJOR"} },
{ 0x0020, std::vector<std::string>{"_UV", "Ch is in undervoltage", "Under-Voltage", "MAJOR"} },
{ 0x0040, std::vector<std::string>{"_ET", "Ch is in external trip", "External Trip", "MAJOR"} },
{ 0x0080, std::vector<std::string>{"_MV", "Ch is in max V", "Max V", "MAJOR"} },
{ 0x0100, std::vector<std::string>{"_ED", "Ch is in external disable", "Ext. Disable", "MAJOR"} },
{ 0x0200, std::vector<std::string>{"_IT", "Ch is in internal trip", "Internal Trip", "MAJOR"} },
{ 0x0400, std::vector<std::string>{"_CE", "Ch is in calibration error", "Calib. Error", "MAJOR"} },
{ 0x0800, std::vector<std::string>{"_UN", "Ch is unplugged", "Unplugged", "MAJOR"} },
{ 0x2000, std::vector<std::string>{ "_OVP", "Ch is in OverVoltage Protection", "Over-Volt Prot.", "MAJOR"} },
{ 0x4000, std::vector<std::string>{ "_PF", "Ch is in Power Fail", "Power Fail", "MAJOR"} },
{ 0x8000, std::vector<std::string>{ "_TE", "Ch is in Temperature Error", "Temp Error", "MAJOR"} },
};
// Map used to generate binary records for the system parameters of type 'PARAM_TYPE_BDSTATUS'.
// There will be a bi and or bo record for each bit status and an mbbi for all of the bits together.
// This maps contains MASK mapped to a vector containing a suffix appended to the record name, Record description, the short string for the MBBI and the alarm status of each mbbi entry.
// - This map is for Board parameters of type 'PARAM_TYPE_CHSTATUS'
statusRecordMap_t recordFieldBdParamBdStatus =
{
{ 0x000, std::vector<std::string>{ "", "", "Ok", "NO_ALARM"} },
{ 0x001, std::vector<std::string>{ "_PF", "Bd is in power-fail status", "Power Fail", "MAJOR"} },
{ 0x002, std::vector<std::string>{ "_FCE", "Bd has a firmware checksum error", "Checksum Err", "MAJOR"} },
{ 0x004, std::vector<std::string>{ "_CEHV", "Bd has calibration error on HV", "Calib. Error", "MAJOR"} },
{ 0x008, std::vector<std::string>{ "_CET", "Bd has a calibration error on temp", "Temp Error", "MAJOR"} },
{ 0x010, std::vector<std::string>{ "_UT", "Bd is in under-temperature status", "Under-temp", "MAJOR"} },
{ 0x020, std::vector<std::string>{ "_OT", "Bd is in over-temperature status", "Over-temp", "MAJOR"} },
};
class CAENHVAsyn : public asynPortDriver
{
public:
CAENHVAsyn(const std::string& portName, int systemType, const std::string& ipAddr, const std::string& userName, const std::string& password);
// Methods that we override from asynPortDriver
virtual asynStatus readFloat64 (asynUser *pasynUser, epicsFloat64 *value);
virtual asynStatus writeFloat64 (asynUser *pasynUser, epicsFloat64 value);
virtual asynStatus readUInt32Digital (asynUser *pasynUser, epicsUInt32 *value, epicsUInt32 mask);
virtual asynStatus writeUInt32Digital (asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask);
virtual asynStatus readOctet (asynUser *pasynUser, char *value, size_t maxChars, size_t *nActual, int *eomReason);
virtual asynStatus writeOctet (asynUser *pasynUser, const char *value, size_t maxChars, size_t *nActual);
virtual asynStatus readInt32 (asynUser *pasynUser, epicsInt32 *value);
virtual asynStatus writeInt32 (asynUser *pasynUser, epicsInt32 value);
// EPICS record prefix. Use for autogeneration of PVs.
static std::string epicsPrefix;
// Crate information output file location
static std::string crateInfoFilePath;
// Whether to only read from the device
static bool readOnly;
private:
// Methods to create EPICS asyn parameters and records for all system, board, and channel parameters
template<typename T>
void createParamFloat(T p, std::map<int, T>& list);
template <typename T>
void createParamBinary(T p, std::map<int, T>& list);
template <typename T>
void createParamMBinary(T p, std::map<int, T>& list, const statusRecordMap_t& recordMap);
template <typename T>
void createParamInteger(T p, std::map<int, T>& list);
template <typename T>
void createParamString(T p, std::map<int, T>& list);
const std::string driverName_;
std::string portName_;
// Crate object
Crate crate;
// System property lists
std::map<int, SystemPropertyInteger> systemPropertyIntegerList;
std::map<int, SystemPropertyString> systemPropertyStringList;
std::map<int, SystemPropertyFloat> systemPropertyFloatList;
// Board parameter lists
std::map<int, BoardParameterReadOnlySizeT> boardParameterReadOnlySizeTList;
std::map<int, BoardParameterReadOnlyString> boardParameterReadOnlyStringList;
std::map<int, BoardParameterNumeric> boardParameterNumericList;
std::map<int, BoardParameterOnOff> boardParameterOnOffList;
std::map<int, BoardParameterChStatus> boardParameterChStatusList;
std::map<int, BoardParameterBdStatus> boardParameterBdStatusList;
// Channel parameter lists
std::map<int, ChannelParameterString> channelParameterStringList;
std::map<int, ChannelParameterNumeric> channelParameterNumericList;
std::map<int, ChannelParameterOnOff> channelParameterOnOffList;
std::map<int, ChannelParameterChStatus> channelParameterChStatusList;
std::map<int, ChannelParameterBinary> channelParameterBinaryList;
};
#endif
|
ISISComputingGroup/CAENHVAsyn | CAENHVAsynApp/src/common.h | <filename>CAENHVAsynApp/src/common.h
#ifndef COMMON_H
#define COMMON_H
/**
*-----------------------------------------------------------------------------
* Title : CAEN HV Asyn module
* ----------------------------------------------------------------------------
* File : common.h
* Author : <NAME>, <EMAIL>
* Created : 2019-08-20
* ----------------------------------------------------------------------------
* Description:
* CAEN HV Power Supplies Common Functions
* ----------------------------------------------------------------------------
* This file is part of l2MpsAsyn. It is subject to
* the license terms in the LICENSE.txt file found in the top-level directory
* of this distribution and at:
* https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
* No part of l2MpsAsyn, including this file, may be
* copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE.txt file.
* ----------------------------------------------------------------------------
**/
#include <string>
#include <sstream>
#include <stdexcept>
#include <iomanip>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <algorithm>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
#include <iostream>
#include "CAENHVWrapper.h"
void printMessage(const std::string& f, const std::string& s);
std::string processParamName(std::string name);
std::string processMode(uint32_t mode);
std::string processUnits(uint16_t units, int16_t exp);
#endif
|
ISISComputingGroup/CAENHVAsyn | CAENHVAsynApp/src/board.h | #ifndef BOARD_H
#define BOARD_H
/**
*-----------------------------------------------------------------------------
* Title : CAEN HV Asyn module
* ----------------------------------------------------------------------------
* File : board.h
* Author : <NAME>, <EMAIL>
* Created : 2019-08-20
* ----------------------------------------------------------------------------
* Description:
* CAEN HV Power supplies Board Class
* ----------------------------------------------------------------------------
* This file is part of l2MpsAsyn. It is subject to
* the license terms in the LICENSE.txt file found in the top-level directory
* of this distribution and at:
* https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
* No part of l2MpsAsyn, including this file, may be
* copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE.txt file.
* ----------------------------------------------------------------------------
**/
#include <string>
#include <sstream>
#include <stdexcept>
#include <iomanip>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
#include <iostream>
#include "CAENHVWrapper.h"
#include "common.h"
#include "board_parameter.h"
#include "channel.h"
class IBoard;
typedef std::shared_ptr<IBoard> Board;
class IBoard
{
public:
IBoard(int h, std::size_t s, std::string m, std::string d, std::size_t n, std::string sn, std::string fw, bool readOnly);
~IBoard();
// Factory method
static Board create(int h, std::size_t s, std::string m, std::string d, std::size_t n, std::string sn, std::string fw, bool readOnly);
void printInfo(std::ostream& stream) const;
void printBoardInfo(std::ostream& stream) const;
std::vector<BoardParameterReadOnlySizeT> getBoardParameterReadOnlySizeTs() { return boardParameterReadOnlySizeTs; };
std::vector<BoardParameterReadOnlyString> getBoardParameterReadOnlyStrings() { return boardParameterReadOnlyStrings; };
std::vector<BoardParameterNumeric> getBoardParameterNumerics() { return boardParameterNumerics; };
std::vector<BoardParameterOnOff> getBoardParameterOnOffs() { return boardParameterOnOffs; };
std::vector<BoardParameterChStatus> getBoardParameterChStatuses() { return boardParameterChStatuses; };
std::vector<BoardParameterBdStatus> getBoardParameterBdStatuses() { return boardParameterBdStatuses; };
std::vector<Channel> getChannels() { return channels; };
private:
void GetBoardParams();
void GetBoardChannels();
int handle;
std::size_t slot;
std::string model;
std::string description;
std::size_t numChannels;
std::string serialNumber;
std::string firmwareRelease;
bool readOnly;
std::vector<BoardParameterReadOnlySizeT> boardParameterReadOnlySizeTs;
std::vector<BoardParameterReadOnlyString> boardParameterReadOnlyStrings;
std::vector<BoardParameterNumeric> boardParameterNumerics;
std::vector<BoardParameterOnOff> boardParameterOnOffs;
std::vector<BoardParameterChStatus> boardParameterChStatuses;
std::vector<BoardParameterBdStatus> boardParameterBdStatuses;
std::vector<Channel> channels;
};
#endif
|
ISISComputingGroup/CAENHVAsyn | CAENHVAsynApp/src/channel.h | <gh_stars>0
#ifndef CHANNEL_H
#define CHANNEL_H
/**
*-----------------------------------------------------------------------------
* Title : CAEN HV Asyn module
* ----------------------------------------------------------------------------
* File : channel.h
* Author : <NAME>, <EMAIL>
* Created : 2019-09-04
* ----------------------------------------------------------------------------
* Description:
* CAEN HV Power supplies Channel Class
* ----------------------------------------------------------------------------
* This file is part of l2MpsAsyn. It is subject to
* the license terms in the LICENSE.txt file found in the top-level directory
* of this distribution and at:
* https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
* No part of l2MpsAsyn, including this file, may be
* copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE.txt file.
* ----------------------------------------------------------------------------
**/
#include <string>
#include <sstream>
#include <stdexcept>
#include <iomanip>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
#include <iostream>
#include "CAENHVWrapper.h"
#include "common.h"
#include "channel_parameter.h"
class IChannel;
typedef std::shared_ptr<IChannel> Channel;
class IChannel
{
public:
IChannel(int h, std::size_t s, std::size_t c, bool readOnly);
~IChannel() {};
// Factory method
static Channel create(int h, std::size_t s, std::size_t c, bool readOnly);
void printInfo(std::ostream& stream) const;
std::vector<ChannelParameterString> getChannelParameterStrings() { return channelParameterStrings; };
std::vector<ChannelParameterNumeric> getChannelParameterNumerics() { return channelParameterNumerics; };
std::vector<ChannelParameterOnOff> getChannelParameterOnOffs() { return channelParameterOnOffs; };
std::vector<ChannelParameterChStatus> getChannelParameterChStatuses() { return channelParameterChStatuses; };
std::vector<ChannelParameterBinary> getChannelParameterBinaries() { return channelParameterBinaries; };
private:
void GetChannelParams();
int handle;
std::size_t slot;
std::size_t channel;
bool readOnly;
std::vector<ChannelParameterString> channelParameterStrings;
std::vector<ChannelParameterNumeric> channelParameterNumerics;
std::vector<ChannelParameterOnOff> channelParameterOnOffs;
std::vector<ChannelParameterChStatus> channelParameterChStatuses;
std::vector<ChannelParameterBinary> channelParameterBinaries;
};
#endif
|
ISISComputingGroup/CAENHVAsyn | CAENHVAsynApp/src/crate.h | #ifndef CRATE_H
#define CRATE_H
/**
*-----------------------------------------------------------------------------
* Title : CAEN HV Asyn module
* ----------------------------------------------------------------------------
* File : crate.h
* Author : <NAME>, <EMAIL>
* Created : 2019-08-20
* ----------------------------------------------------------------------------
* Description:
* CAEN HV Power Supplies Crate Class
* ----------------------------------------------------------------------------
* This file is part of l2MpsAsyn. It is subject to
* the license terms in the LICENSE.txt file found in the top-level directory
* of this distribution and at:
* https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
* No part of l2MpsAsyn, including this file, may be
* copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE.txt file.
* ----------------------------------------------------------------------------
**/
#include <string>
#include <sstream>
#include <stdexcept>
#include <iomanip>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
#include <iostream>
#include "CAENHVWrapper.h"
#include "common.h"
#include "board.h"
#include "system_property.h"
class SysProp;
template<typename T>
class SysPropT;
class ICrate;
typedef std::shared_ptr<ICrate> Crate;
class ICrate
{
public:
ICrate(int systemType, const std::string& ipAddr, const std::string& userName, const std::string& password, const bool readOnly);
~ICrate();
// Factory method
static Crate create(int systemType, const std::string& ipAddr, const std::string& userName, const std::string& password, const bool readOnly);
void printInfo(std::ostream& stream) const;
void printCrateMap(std::ostream& stream) const;
std::vector<SystemPropertyInteger> getSystemPropertyIntegers() { return systemPropertyIntegers; };
std::vector<SystemPropertyFloat> getSystemPropertyFloats() { return systemPropertyFloats; };
std::vector<SystemPropertyString> getSystemPropertyStrings() { return systemPropertyStrings; };
std::vector<Board> getBoards() { return boards; };
private:
int InitSystem(int systemType, const std::string& ipAddr, const std::string& userName, const std::string& password) const;
void GetPropList();
void GetCrateMap();
template <typename T>
void printProperties(std::ostream& stream, const std::string& type, const T& pv) const;
int handle;
bool readOnly;
// Number of slot in the crate
std::size_t numSlots;
// Slots in the crate
std::vector<Board> boards;
// Crate properties
std::vector<SystemPropertyInteger> systemPropertyIntegers;
std::vector<SystemPropertyFloat> systemPropertyFloats;
std::vector<SystemPropertyString> systemPropertyStrings;
};
#endif
|
ISISComputingGroup/CAENHVAsyn | CAENHVAsynApp/src/channel_parameter.h | <reponame>ISISComputingGroup/CAENHVAsyn<gh_stars>0
#ifndef CHANNEL_PARAMETER_H
#define CHANNEL_PARAMETER_H
/**
*-----------------------------------------------------------------------------
* Title : CAEN HV Asyn module
* ----------------------------------------------------------------------------
* File : board_parameter.h
* Author : <NAME>, <EMAIL>
* Created : 2019-08-20
* ----------------------------------------------------------------------------
* Description:
* CAEN HV Power supplies Board Parameter Class
* ----------------------------------------------------------------------------
* This file is part of l2MpsAsyn. It is subject to
* the license terms in the LICENSE.txt file found in the top-level directory
* of this distribution and at:
* https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
* No part of l2MpsAsyn, including this file, may be
* copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE.txt file.
* ----------------------------------------------------------------------------
**/
#include <string>
#include <sstream>
#include <stdexcept>
#include <iomanip>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <memory>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
#include <iostream>
#include "CAENHVWrapper.h"
#include "common.h"
#include "board_parameter.h"
class IChannelParameterNumeric;
class IChannelParameterOnOff;
class IChannelParameterChStatus;
class IChannelParameterBinary;
class IChannelParameterString;
class IChannelName;
// Shared pointer types
typedef std::shared_ptr< IChannelParameterNumeric > ChannelParameterNumeric;
typedef std::shared_ptr< IChannelParameterOnOff > ChannelParameterOnOff;
typedef std::shared_ptr< IChannelParameterChStatus > ChannelParameterChStatus;
typedef std::shared_ptr< IChannelParameterBinary > ChannelParameterBinary;
typedef std::shared_ptr< IChannelParameterString > ChannelParameterString;
typedef std::shared_ptr< IChannelName > ChannelName;
template<typename T>
class ChannelParameterBase
{
public:
ChannelParameterBase(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
virtual ~ChannelParameterBase() {};
std::string getMode() { return modeStr; };
std::string getEpicsParamName() { return epicsParamName; };
std::string getEpicsRecordName() { return epicsRecordName; };
std::string getEpicsDesc() { return epicsDesc; };
virtual void printInfo(std::ostream& stream) const;
virtual void printValOrError(std::ostream& stream) const;
virtual T getVal() const;
virtual void setVal(T value) const;
protected:
int handle;
std::size_t slot;
std::size_t channel;
std::string param;
uint32_t mode;
std::string type;
std::string modeStr;
std::string epicsParamName;
std::string epicsRecordName;
std::string epicsDesc;
};
// Class for Numeric parameters
class IChannelParameterNumeric : public ChannelParameterBase<float>
{
public:
IChannelParameterNumeric(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
~IChannelParameterNumeric() {};
// Factory method
static ChannelParameterNumeric create(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
float getMinVal() const { return minVal; };
float getMaxVal() const { return maxVal; };
std::string getUnits() const { return units; };
virtual void printInfo(std::ostream& stream) const;
private:
float minVal;
float maxVal;
std::string units;
};
// Class for OnOff parameters
class IChannelParameterOnOff : public ChannelParameterBase<uint32_t>
{
public:
IChannelParameterOnOff(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
~IChannelParameterOnOff() {};
// Factory method
static ChannelParameterOnOff create(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
std::string getOnState() const { return onState; };
std::string getOffState() const { return offState; };
virtual void printInfo(std::ostream& stream) const;
private:
std::string onState;
std::string offState;
};
// Class for ChStatus parameters
class IChannelParameterChStatus : public ChannelParameterBase<uint32_t>
{
public:
IChannelParameterChStatus(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
~IChannelParameterChStatus() {};
// Factory method
static ChannelParameterChStatus create(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
virtual void printInfo(std::ostream& stream) const;
};
// Class for Binary parameters
class IChannelParameterBinary : public ChannelParameterBase<int32_t>
{
public:
IChannelParameterBinary(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
~IChannelParameterBinary() {};
// Factory method
static ChannelParameterBinary create(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
virtual void printInfo(std::ostream& stream) const;
};
// Class for String Parameters
class IChannelParameterString : public ChannelParameterBase<std::string>
{
public:
IChannelParameterString(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
~IChannelParameterString() {};
// Factory method
static ChannelParameterString create(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
};
// Class for Channel name (not really a parameter as CAEN defines it)
class IChannelName : public IChannelParameterString
{
public:
IChannelName(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
~IChannelName() {};
// Factory method
static ChannelName create(int h, std::size_t s, std::size_t c, const std::string& p, uint32_t m);
virtual std::string getVal() const;
virtual void setVal(std::string value) const;
};
#endif
|
mwdchang/delphi | external/eigen/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h | <reponame>mwdchang/delphi<filename>external/eigen/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2014 <NAME> <<EMAIL>>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#if defined(EIGEN_USE_THREADS) && !defined(EIGEN_CXX11_TENSOR_TENSOR_DEVICE_THREAD_POOL_H)
#define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_THREAD_POOL_H
namespace Eigen {
// Runs an arbitrary function and then calls Notify() on the passed in
// Notification.
template <typename Function, typename... Args> struct FunctionWrapperWithNotification
{
static void run(Notification* n, Function f, Args... args) {
f(args...);
if (n) {
n->Notify();
}
}
};
template <typename Function, typename... Args> struct FunctionWrapperWithBarrier
{
static void run(Barrier* b, Function f, Args... args) {
f(args...);
if (b) {
b->Notify();
}
}
};
template <typename SyncType>
static EIGEN_STRONG_INLINE void wait_until_ready(SyncType* n) {
if (n) {
n->Wait();
}
}
// An abstract interface to a device specific memory allocator.
class Allocator {
public:
virtual ~Allocator() {}
virtual void* allocate(size_t num_bytes) const = 0;
virtual void deallocate(void* buffer) const = 0;
};
// Build a thread pool device on top the an existing pool of threads.
struct ThreadPoolDevice {
// The ownership of the thread pool remains with the caller.
ThreadPoolDevice(ThreadPoolInterface* pool, int num_cores, Allocator* allocator = NULL)
: pool_(pool), num_threads_(num_cores), allocator_(allocator) { }
EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const {
return allocator_ ? allocator_->allocate(num_bytes)
: internal::aligned_malloc(num_bytes);
}
EIGEN_STRONG_INLINE void deallocate(void* buffer) const {
if (allocator_) {
allocator_->deallocate(buffer);
} else {
internal::aligned_free(buffer);
}
}
EIGEN_STRONG_INLINE void* allocate_temp(size_t num_bytes) const {
return allocate(num_bytes);
}
EIGEN_STRONG_INLINE void deallocate_temp(void* buffer) const {
deallocate(buffer);
}
template<typename Type>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Type get(Type data) const {
return data;
}
EIGEN_STRONG_INLINE void memcpy(void* dst, const void* src, size_t n) const {
#ifdef __ANDROID__
::memcpy(dst, src, n);
#else
// TODO(rmlarsen): Align blocks on cache lines.
// We have observed that going beyond 4 threads usually just wastes
// CPU cycles due to the threads competing for memory bandwidth, so we
// statically schedule at most 4 block copies here.
const size_t kMinBlockSize = 32768;
typedef TensorCostModel<ThreadPoolDevice> CostModel;
const size_t num_threads = CostModel::numThreads(n, TensorOpCost(1.0, 1.0, 0), 4);
if (n <= kMinBlockSize || num_threads < 2) {
::memcpy(dst, src, n);
} else {
const char* src_ptr = static_cast<const char*>(src);
char* dst_ptr = static_cast<char*>(dst);
const size_t blocksize = (n + (num_threads - 1)) / num_threads;
Barrier barrier(static_cast<int>(num_threads - 1));
// Launch the last 3 blocks on worker threads.
for (size_t i = 1; i < num_threads; ++i) {
enqueue_with_barrier(&barrier, [n, i, src_ptr, dst_ptr, blocksize] {
::memcpy(dst_ptr + i * blocksize, src_ptr + i * blocksize,
numext::mini(blocksize, n - (i * blocksize)));
});
}
// Launch the first block on the main thread.
::memcpy(dst_ptr, src_ptr, blocksize);
barrier.Wait();
}
#endif
}
EIGEN_STRONG_INLINE void memcpyHostToDevice(void* dst, const void* src, size_t n) const {
memcpy(dst, src, n);
}
EIGEN_STRONG_INLINE void memcpyDeviceToHost(void* dst, const void* src, size_t n) const {
memcpy(dst, src, n);
}
EIGEN_STRONG_INLINE void memset(void* buffer, int c, size_t n) const {
::memset(buffer, c, n);
}
EIGEN_STRONG_INLINE int numThreads() const {
return num_threads_;
}
// Number of theads available in the underlying thread pool. This number can
// be different from the value returned by numThreads().
EIGEN_STRONG_INLINE int numThreadsInPool() const {
return pool_->NumThreads();
}
EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const {
return l1CacheSize();
}
EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const {
// The l3 cache size is shared between all the cores.
return l3CacheSize() / num_threads_;
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int majorDeviceVersion() const {
// Should return an enum that encodes the ISA supported by the CPU
return 1;
}
template <class Function, class... Args>
EIGEN_STRONG_INLINE Notification* enqueue(Function&& f,
Args&&... args) const {
Notification* n = new Notification();
pool_->Schedule(
std::bind(&FunctionWrapperWithNotification<Function, Args...>::run, n,
std::move(f), args...));
return n;
}
template <class Function, class... Args>
EIGEN_STRONG_INLINE void enqueue_with_barrier(Barrier* b, Function&& f,
Args&&... args) const {
pool_->Schedule(
std::bind(&FunctionWrapperWithBarrier<Function, Args...>::run, b,
std::move(f), args...));
}
template <class Function, class... Args>
EIGEN_STRONG_INLINE void enqueueNoNotification(Function&& f,
Args&&... args) const {
if (sizeof...(args) > 0) {
pool_->Schedule(std::bind(std::move(f), args...));
} else {
pool_->Schedule(std::move(f));
}
}
// Returns a logical thread index between 0 and pool_->NumThreads() - 1 if
// called from one of the threads in pool_. Returns -1 otherwise.
EIGEN_STRONG_INLINE int currentThreadId() const {
return pool_->CurrentThreadId();
}
// WARNING: This function is synchronous and will block the calling thread.
//
// Synchronous parallelFor executes f with [0, n) arguments in parallel and
// waits for completion. F accepts a half-open interval [first, last). Block
// size is chosen based on the iteration cost and resulting parallel
// efficiency. If block_align is not nullptr, it is called to round up the
// block size.
void parallelFor(Index n, const TensorOpCost& cost,
std::function<Index(Index)> block_align,
std::function<void(Index, Index)> f) const {
// Compute small problems directly in the caller thread.
if (n <= 1 || numThreads() == 1 ||
CostModel::numThreads(n, cost, static_cast<int>(numThreads())) == 1) {
f(0, n);
return;
}
// Compute block size and total count of blocks.
ParallelForBlock block = CalculateParallelForBlock(n, cost, block_align);
// Recursively divide size into halves until we reach block_size.
// Division code rounds mid to block_size, so we are guaranteed to get
// block_count leaves that do actual computations.
Barrier barrier(static_cast<unsigned int>(block.count));
std::function<void(Index, Index)> handleRange;
handleRange = [=, &handleRange, &barrier, &f](Index firstIdx,
Index lastIdx) {
while (lastIdx - firstIdx > block.size) {
// Split into halves and schedule the second half on a different thread.
const Index midIdx = firstIdx + divup((lastIdx - firstIdx) / 2, block.size) * block.size;
pool_->Schedule([=, &handleRange]() { handleRange(midIdx, lastIdx); });
lastIdx = midIdx;
}
// Single block or less, execute directly.
f(firstIdx, lastIdx);
barrier.Notify();
};
if (block.count <= numThreads()) {
// Avoid a thread hop by running the root of the tree and one block on the
// main thread.
handleRange(0, n);
} else {
// Execute the root in the thread pool to avoid running work on more than
// numThreads() threads.
pool_->Schedule([=, &handleRange]() { handleRange(0, n); });
}
barrier.Wait();
}
// Convenience wrapper for parallelFor that does not align blocks.
void parallelFor(Index n, const TensorOpCost& cost,
std::function<void(Index, Index)> f) const {
parallelFor(n, cost, NULL, std::move(f));
}
// WARNING: This function is asynchronous and will not block the calling thread.
//
// Asynchronous parallelFor executes f with [0, n) arguments in parallel
// without waiting for completion. When the last block finished, it will call
// 'done' callback. F accepts a half-open interval [first, last). Block size
// is chosen based on the iteration cost and resulting parallel efficiency. If
// block_align is not nullptr, it is called to round up the block size.
void parallelForAsync(Index n, const TensorOpCost& cost,
std::function<Index(Index)> block_align,
std::function<void(Index, Index)> f,
std::function<void()> done) const {
// Compute block size and total count of blocks.
ParallelForBlock block = CalculateParallelForBlock(n, cost, block_align);
ParallelForAsyncContext* const ctx =
new ParallelForAsyncContext(block.count, std::move(f), std::move(done));
// Recursively divide size into halves until we reach block_size.
// Division code rounds mid to block_size, so we are guaranteed to get
// block_count leaves that do actual computations.
ctx->handle_range = [this, ctx, block](Index firstIdx, Index lastIdx) {
while (lastIdx - firstIdx > block.size) {
// Split into halves and schedule the second half on a different thread.
const Index midIdx = firstIdx + divup((lastIdx - firstIdx) / 2, block.size) * block.size;
pool_->Schedule(
[ctx, midIdx, lastIdx]() { ctx->handle_range(midIdx, lastIdx); });
lastIdx = midIdx;
}
// Single block or less, execute directly.
ctx->f(firstIdx, lastIdx);
// Call 'done' callback if it was the last block.
if (ctx->count.fetch_sub(1) == 1) {
(ctx->done)();
// We can't delete ctx right now, because it will deallocate the closure
// we are currently in.
pool_->Schedule([ctx]() { delete ctx; });
}
};
// Execute the root in the thread pool.
pool_->Schedule([ctx, n]() { ctx->handle_range(0, n); });
}
// Convenience wrapper for parallelForAsync that does not align blocks.
void parallelForAsync(Index n, const TensorOpCost& cost,
std::function<void(Index, Index)> f,
std::function<void()> done) const {
parallelForAsync(n, cost, NULL, std::move(f), std::move(done));
}
// Thread pool accessor.
ThreadPoolInterface* getPool() const { return pool_; }
// Allocator accessor.
Allocator* allocator() const { return allocator_; }
private:
typedef TensorCostModel<ThreadPoolDevice> CostModel;
// For parallelForAsync we must keep passed in closures on the heap, and
// delete them only after `done` callback finished.
struct ParallelForAsyncContext {
ParallelForAsyncContext(Index count, std::function<void(Index, Index)> f,
std::function<void()> done)
: count(count), f(std::move(f)), done(std::move(done)) {}
std::atomic<Index> count;
std::function<void(Index, Index)> f;
std::function<void()> done;
std::function<void(Index, Index)> handle_range;
};
struct ParallelForBlock {
Index size; // block size
Index count; // number of blocks
};
// Calculates block size based on (1) the iteration cost and (2) parallel
// efficiency. We want blocks to be not too small to mitigate parallelization
// overheads; not too large to mitigate tail effect and potential load
// imbalance and we also want number of blocks to be evenly dividable across
// threads.
ParallelForBlock CalculateParallelForBlock(
const Index n, const TensorOpCost& cost,
std::function<Index(Index)> block_align) const {
const double block_size_f = 1.0 / CostModel::taskSize(1, cost);
const Index max_oversharding_factor = 4;
Index block_size = numext::mini(
n, numext::maxi<Index>(
divup<Index>(n, max_oversharding_factor * numThreads()),
block_size_f));
const Index max_block_size = numext::mini(n, 2 * block_size);
if (block_align) {
Index new_block_size = block_align(block_size);
eigen_assert(new_block_size >= block_size);
block_size = numext::mini(n, new_block_size);
}
Index block_count = divup(n, block_size);
// Calculate parallel efficiency as fraction of total CPU time used for
// computations:
double max_efficiency =
static_cast<double>(block_count) /
(divup<int>(block_count, numThreads()) * numThreads());
// Now try to increase block size up to max_block_size as long as it
// doesn't decrease parallel efficiency.
for (Index prev_block_count = block_count;
max_efficiency < 1.0 && prev_block_count > 1;) {
// This is the next block size that divides size into a smaller number
// of blocks than the current block_size.
Index coarser_block_size = divup(n, prev_block_count - 1);
if (block_align) {
Index new_block_size = block_align(coarser_block_size);
eigen_assert(new_block_size >= coarser_block_size);
coarser_block_size = numext::mini(n, new_block_size);
}
if (coarser_block_size > max_block_size) {
break; // Reached max block size. Stop.
}
// Recalculate parallel efficiency.
const Index coarser_block_count = divup(n, coarser_block_size);
eigen_assert(coarser_block_count < prev_block_count);
prev_block_count = coarser_block_count;
const double coarser_efficiency =
static_cast<double>(coarser_block_count) /
(divup<int>(coarser_block_count, numThreads()) * numThreads());
if (coarser_efficiency + 0.01 >= max_efficiency) {
// Taking it.
block_size = coarser_block_size;
block_count = coarser_block_count;
if (max_efficiency < coarser_efficiency) {
max_efficiency = coarser_efficiency;
}
}
}
return {block_size, block_count};
}
ThreadPoolInterface* pool_;
int num_threads_;
Allocator* allocator_;
};
} // end namespace Eigen
#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_THREAD_POOL_H
|
TheBadZhang/OJ | usx/special/60/6036-2.c | #include<stdio.h>
main(){puts("4562");} |
TheBadZhang/OJ | usx/special/60/6047.c | #include <stdio.h>
int main () {
int n, m;
while (~scanf ("%d %d", &n, &m)) { // 处理多组输入
int i, j;
int matrix[10][10]; // 定义一个矩阵(二维数组)
for (i = 0; i < n; i ++) {
for (j = 0; j < m; j ++) {
scanf ("%d", &matrix[i][j]); // 向矩阵输入数据
}
}
int maxi = 0, maxj = 0, mini = 0, minj = 0;
// 假定 max 和 min 为 (0,0) 上的元素
for (i = 0; i < n; i ++) {
for (j = 0; j < m; j++) { // 遍历矩阵(二维数组(
if (matrix[i][j] > matrix[maxi][maxj]) {
maxi = i; // 比较、找出最大值
maxj = j;
}
if (matrix [i][j] < matrix [mini][minj]) {
mini = i; // 比较、找出最小值
minj = j;
}
}
}
// 输出结果
printf ("max=%d row=%d col=%d\n", matrix[maxi][maxj], maxi, maxj);
printf ("min=%d row=%d col=%d\n", matrix[mini][minj], mini, minj);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6016.c | #include <stdio.h>
double e (double i) {
double r = 2, s = 1;
int d;
for (d = 2; s >= i; d++) {
s /= d;
r += s;
}
return r;
}
int main () {
double i;
while (~scanf ("%lf", &i)) {
printf ("%.18lf\n", e(i));
}
return 0;
} |
TheBadZhang/OJ | usx/special/91/9102.c | #include <stdio.h>
int main () {
const double pi = 3.14159;
double r;
scanf ("%lf", &r);
printf ("%.2lf\n", 2*pi*r);
printf ("%.2lf\n", pi*r*r);
return 0;
} |
TheBadZhang/OJ | hdu/2000/20xx/2013.c | <gh_stars>1-10
#include<stdio.h>
int n,r[32]={1};main(){for(;n++<32;){r[n]=2*(r[n-1]+1);}while(~scanf("%d",&n)){printf("%d\n",r[n-1]);}}
|
TheBadZhang/OJ | usx/special/60/6044.c | <filename>usx/special/60/6044.c
#include <stdio.h>
int search (int* list, int size, int d) {
int start = 0, end = size, mid; // 二分搜索查找插入的位置
while (start <= end) {
mid = (start+end)/2;
if (d <= list [mid]) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return start;
}
void moveRight (int* list, int size, int pos) {
int i = size; // 将数组pos位置及右边的元素,向右移动
for (; i > pos; i--) {
list [i] = list [i-1];
}
}
void insert (int* list, int size, int i) {
int pos = search (list, size, i);
// 通过搜索得到插入的位置
moveRight (list, size, pos);
// 移动数据并插入
list [pos] = i;
}
void insertSort (int* list, int size) {
int i, t; // 将后面的元素反复插入到前面已经排好序的数组里面
for (i = 1; i < size; i ++) {
t = list [i]; // 就可以得到一个全都有序的数组了
insert (list, i, t);
}
}
void print (int* list, int size) {
int i; // 输出数组当前元素
for (i = 0; i < size; i ++) {
printf ("%3d", list [i]);
}
printf ("\n");
}
int main () {
int list [100];
int n, i;
while (~scanf ("%d", &n)) {
for (i = 0; i < n; i++) { // 读入数据
scanf ("%d", &list [i]);
}
// print (list, n);
insertSort (list, n);
print (list, n);
scanf ("%d", &i);
insert (list, n, i);
print (list, n+1);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6033.c | <filename>usx/special/60/6033.c
#include <stdio.h>
int main () {
int n;
while (~scanf ("%d", &n)) {
if (n >= 90) {
printf ("A\n");
} else if (n >= 80) {
printf ("B\n");
} else if (n >= 70) {
printf ("C\n");
} else if (n >= 60) {
printf ("D\n");
} else {
printf ("E\n");
}
}
} |
TheBadZhang/OJ | usx/special/60/6087.c | #include <stdio.h>
#include <string.h>
int main () {
int n;
while (~scanf ("%d\n", &n)) {
int i;
int score, maxscore;
char name[80], maxname[80], num[80];
for (i = 0; i < n; i++) {
scanf ("%s %s %d\n", num, name, &score);
if (i == 0 || score > maxscore) {
strcpy (maxname, name);
maxscore = score;
}
}
printf ("%s %d\n", maxname, maxscore);
}
return 0;
} |
TheBadZhang/OJ | usx/special/91/9106.c | #include <stdio.h>
int main () {
double a, b;
scanf ("%lf %lf", &a, &b);
printf ("%.2lf\n", -b/a);
return 0;
} |
TheBadZhang/OJ | usx/special/91/9104.c | <gh_stars>1-10
#include <stdio.h>
int main () {
float a, b, h;
scanf ("%f %f %f", &a, &b, &h);
printf ("%.2f", (a+b)*h/2);
return 0;
} |
TheBadZhang/OJ | usx/special/60/6076.c | #include <stdio.h>
#include <ctype.h>
#include <string.h>
int main () {
int n;
char str [100];
while (~scanf ("%d\n", &n)) {
int i, j;
int lowercase = 0, capital = 0, space = 0, sign = 0;
for (i = 0; i < n; i++) {
gets (str);
for (j = 0; j < strlen(str); j++) {
if (isspace (str[j])) space ++;
else if (islower (str[j])) lowercase ++;
else if (isupper (str[j])) capital ++;
else if (ispunct (str[j])) sign ++;
}
}
printf ("lowercase=%d capital=%d space=%d sign=%d\n",
lowercase, capital, space, sign);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6025.c | <filename>usx/special/60/6025.c
#include <stdio.h>
int main () {
int m, a, b, c;
for (m = 100; m < 1000; ++m) {
a = m / 100;
b = m / 10 % 10;
c = m % 10;
if (m == a*a*a + b*b*b + c*c*c) {
printf ("%d=%d*%d*%d+%d*%d*%d+%d*%d*%d\n",
m, a, a, a, b, b, b, c, c, c);
}
}
return 0;
}
|
TheBadZhang/OJ | usx/special/92/9218.c | <gh_stars>1-10
#include <stdio.h>
#include <math.h>
int main () {
int x1, y1, x2, y2;
while (~scanf ("%d %d %d %d", &x1, &y1, &x2, &y2)) {
printf ("%d\n", abs(x2-x1)*abs(y2-y1));
}
return 0;
} |
TheBadZhang/OJ | usx/special/92/9226.c | #include <stdio.h>
int gcd (int m, int n) {
return n?gcd(n,m%n):m;
}
int main () {
int T, m, n, i, mini;
scanf ("%d", &T);
while (T--) {
scanf ("%d %d %d", &i, &m, &n);
m *= i;
mini = gcd (m, n);
m /= mini; // 计算最大公约数
n /= mini; // 计算
if (m%n == 0) { // 可以约成整数
printf ("%d\n", m/n);
} else { // 不能约成整数
if (m > n) {// 如果分子大于分母
printf ("%d %d %d\n", m/n, m%n, n);
// 输出假分数
} else {
printf ("%d %d\n", m, n);
// 输出普通分数
}
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/92/9205.c | <filename>usx/special/92/9205.c
#include <stdio.h>
int main () {
int a;
while (~scanf ("%d", &a)) {
if (a%2) {
printf ("odd\n");
} else {
printf ("even\n");
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6042.c | #include <stdio.h>
int main () {
int n;
int v[25][25] = {0};
while (~scanf ("%d", &n)) {
int i,j,c=1;
for (i = 0; i <= n/2; i++, c+=3*(n-2*i+1)) {
for (j = i; j < n-i-1; j++, c++) {
v[j][i] = c;
v[n-i-1][j] = (n-2*i-1)+c;
v[n-j-1][n-i-1] = 2*(n-2*i-1)+c;
v [i][n-j-1] = 3*(n-2*i-1)+c;
}
}
if (n&1) {
v[n/2][n/2] = n*n;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (j)
printf ("%4d",v[i][j]);
else
printf ("%2d",v[i][j]);
}
printf ("\n");
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6078.c | <reponame>TheBadZhang/OJ
#include <stdio.h>
#include <math.h>
int isPrime (int n) {
int i;
if (!n&1) return 0;
for (i = 3; i <= sqrt (n); i+=2) {
if (n%i == 0) return 0;
}
return 1;
}
int main () {
int n;
while (~scanf ("%d", &n)) {
if (isPrime (n)) {
printf ("YES\n");
} else {
printf ("NO\n");
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6010.c | #include <stdio.h>
int main () {
int n;
while (~scanf ("%d", &n)) {
if (n%3 == 0 && n%5 == 0) {
printf ("YES\n");
} else {
printf ("NO\n");
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6082.c | #include <stdio.h>
#include <stdlib.h>
void swap (int* a, int* b) {
int c = *a;
*a = *b;
*b = c;
}
struct element {
int value;
int i, j;
} s[225];
int cmp (const void* a, const void* b) {
// return (((struct element*)a) -> value - ((struct element*)b) -> value) ?
// (((struct element*)a) -> value - ((struct element*)b) -> value) :
// (((struct element*)a) -> i - ((struct element*)b) -> i) ?
// (((struct element*)a) -> i - ((struct element*)b) -> i) :
// (((struct element*)a) -> j - ((struct element*)b) -> j);
return ((struct element*)a) -> value - ((struct element*)b) -> value;
}
// 这个地方从比较变成 - 之后排序结果就是正确的了
int main () {
int n;
int matrix [13][13];
while (~scanf ("%d", &n)) {
int i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf ("%d", &matrix[i][j]);
s [i*n + j].value = matrix[i][j];
s [i*n + j].i = i;
s [i*n + j].j = j;
}
}
qsort (s, n*n, sizeof (struct element), cmp);
swap (&matrix[s[0].i][s[0].j], &matrix [0][0]);
swap (&matrix[s[1].i][s[1].j], &matrix [0][n-1]);
swap (&matrix[s[2].i][s[2].j], &matrix [n-1][0]);
swap (&matrix[s[3].i][s[3].j], &matrix [n-1][n-1]);
swap (&matrix[s[n*n-1].i][s[n*n-1].j], &matrix [n/2][n/2]);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
printf ("%d ", matrix[i][j]);
}
printf ("\n");
}
printf ("\n");
}
return 0;
} |
TheBadZhang/OJ | usx/special/92/9223.c | #include <stdio.h>
int main () {
int T, m, n, i, mini;
scanf ("%d", &T);
while (T--) {
scanf ("%d %d", &m, &n);
mini = m>n ? n : m;
for (i = 1; i <= mini; i++) {
if (n%i == 0 && m%i == 0) {
if (i != 1) printf (" ");
printf ("%d", i);
}
}
printf ("\n");
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6070.c | <gh_stars>1-10
#include <stdio.h>
#include <math.h>
int main () {
int n, i;
double a, b, c;
scanf ("%d", &n);
for (i = 0; i < n; i ++) {
scanf ("%lf %lf %lf", &a, &b, &c);
printf ("%.2lf %.2lf %.2lf\n", sin(a), sqrt(b), log(c));
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6020-2.c | #include<stdio.h>
main(){puts("YES");} |
TheBadZhang/OJ | usx/special/60/6067-2.c | <filename>usx/special/60/6067-2.c
#include <stdio.h>
int main () {
int i;
while (~scanf ("%x", &i)) {
printf ("%d\n", i);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6001.c | <gh_stars>1-10
#include <stdio.h>
int main () {
printf ("I am a student.\nI love China.\n");
return 0;
} |
TheBadZhang/OJ | usx/special/60/6029.c | #include <stdio.h>
double abs (double x) {
if (x < 0) return -x;
else return x;
}
double sqrt (double x) {
double xn = 1, a = x;
while (abs(xn-(xn+a/xn)/2.0) >= 1e-7) {
// 1e-5 所计算得到的精度并不能满足题目的要求,所以我直接拉了两个量级
xn = (xn+a/xn)/2.0;
}
return xn;
}
int main () {
double n;
while (~scanf("%lf", &n)) {
printf ("%.6lf\n", sqrt (n));
}
return 0;
} |
TheBadZhang/OJ | usx/special/91/9110-2.c | <reponame>TheBadZhang/OJ
#include <stdio.h>
main(){puts("53 37 16");} |
TheBadZhang/OJ | usx/special/92/9209.c | <reponame>TheBadZhang/OJ<filename>usx/special/92/9209.c
#include <stdio.h>
int main () {
int s, w, p;
float price, rate;
while (~scanf ("%d %d %d", &s, &w, &p)) {
if (w < 2) {
rate = 0.98;
} else if (w < 4) {
rate = 0.96;
} else if (w < 6) {
rate = 0.94;
} else {
rate = 0.92;
}
if (s < 300) {
rate += 0.02;
}
price = s*w*p*rate;
printf ("%.2f\n", price);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6065.c | <filename>usx/special/60/6065.c<gh_stars>1-10
#include <stdio.h>
int main () {
int n, i;
double x;
while (~scanf ("%d %lf", &n, &x)) {
if (n > 15 || n < 0) printf ("-10000.000000\n");
else {
double hermite [20] = { 1 };
hermite [1] = 2*x;
for (i = 2; i <= n; i ++)
hermite [i] = hermite[1]*hermite[i-1] - 2*(i-1)*hermite[i-2];
printf ("%.6lf\n", hermite [n]);
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/91/9109.c | <filename>usx/special/91/9109.c
#include <stdio.h>
int main () {
int a, c;
double b, d;
scanf ("%d%lf %d%lf", &a, &b, &c, &d);
printf ("%.2lf %.2lf", b+c, a+d);
return 0;
} |
TheBadZhang/OJ | usx/special/60/6069.c | <gh_stars>1-10
#include <stdio.h>
int main () {
int n, nn;
scanf ("%d", &n);
int max, min, sum;
int i, ii, j;
for (i = 0; i < n; i++) {
scanf ("%d", &nn);
sum = 0;
for (j = 0; j < nn; j++) {
scanf ("%d", &ii);
if (j == 0) {
max = min = ii;
}
sum += ii;
if (max < ii) max = ii;
if (min > ii) min = ii;
}
printf ("%d %d %d\n", max, min, sum/nn);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6049.c | #include <stdio.h>
int m,n,i,j;
int v[200][200] = {0};
int max_min (int ns, int ms) {
int ii, flag = 1;
for (ii = 0; ii < m; ii++) {
if (v[ns][ii] > v[ns][ms]) {
flag = 0;
}
}
for (ii = 0; ii < n; ii++) {
if (v[ii][ms] < v[ns][ms]) {
flag = 0;
}
}
return flag;
}
int main () {
while (~scanf ("%d %d", &n, &m)) {
int count = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf ("%d", &v[i][j]);
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (max_min (i, j)) {
printf ("%d %d %d\n", v[i][j], i, j);
count ++;
}
}
}
if (count == 0) {
printf ("Not\n");
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6030.c | <filename>usx/special/60/6030.c
#include <stdio.h>
#include <math.h>
double f (double x) {
return 2*x*x*x-4*x*x+3*x-7;
}
double df (double x) {
return 6*x*x-8*x+3;
}
int main () {
double x = 1.5;
while (fabs(f(x)) >= 1e-5) {
x = x - f(x)/df(x);
}
printf ("%.6lf\n", x);
return 0;
} |
TheBadZhang/OJ | usx/special/92/9215.c | #include <stdio.h>
int isTriangle (double a, double b, double c) {
if (a+c <= b || a+b <= c || b+c <= a) {
return 0;
} else {
return 1;
}
}
int main () {
double a, b, c;
while (~scanf ("%lf %lf %lf", &a, &b, &c)) {
if (isTriangle (a, b, c)) {
if (a == b && b == c) {
printf ("equilateral triangle\n");
} else if (a == b || a == c || b == c) {
printf ("isosceles triangle\n");
} else {
printf ("scalene triangle\n");
}
} else {
printf ("not triangle\n");
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/92/9206.c | <filename>usx/special/92/9206.c
#include <stdio.h>
double f(double x) {
if (x < 0) {
return 0;
} else if (x < 10) {
return 2*x;
} else if (x < 50) {
return 2*x + 1;
} else {
return x/2.0+50;
}
}
int main () {
double x;
while (~scanf ("%lf", &x)) {
printf ("%.2lf\n", f(x));
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6031.c | <reponame>TheBadZhang/OJ
#include <stdio.h>
#include <math.h>
double f (double x) {
return 2*x*x*x-4*x*x+3*x-7;
}
int main () {
double l = -10.0, r = 10.0, m;
while (fabs (r-l) >= 1e-5) {
m = (l+r)/2.0;
if (f(l) < 0.0 && f(r) > 0.0) {
if (f(m) == 0.0) {
l = r = m;
} else if (f(m) < 0) {
l = m;
} else {
r = m;
}
} else {
if (f(m) == 0.0) {
l = r = m;
} else if (f(m) < 0) {
r = m;
} else {
l = m;
}
}
}
printf ("%.6lf %.6lf\n", l, r);
return 0;
} |
TheBadZhang/OJ | usx/special/60/6052.c | <reponame>TheBadZhang/OJ
#include <string.h>
#include <stdio.h>
#include <ctype.h>
int main () {
int n;
char str[100];
char sstr [300] = { '\0' };
while (gets(str)) {
strcat (sstr, str);
gets(str);
strcat (sstr, str);
gets(str);
strcat (sstr, str);
int l = strlen (sstr);
int inWord = 0;
int space = 0;
int word = 0;
for (n = 0; n < l; n++) {
if (isalpha (sstr[n])) {
inWord = 1;
} else {
if (inWord) {
word++;
}
inWord = 0;
}
if (sstr[n] == ' ') {
space ++;
}
}
printf ("%d %d\n", word, space);
memset (sstr, 0, 300*sizeof(char));
}
return 0;
} |
TheBadZhang/OJ | usx/special/91/9119.c | <reponame>TheBadZhang/OJ<filename>usx/special/91/9119.c
#include <stdio.h>
int main () {
int l = 0, i;
scanf ("%d", &i);
do {
l ++;
i /= 10;
} while (i > 0);
printf ("%d", l);
return 0;
} |
TheBadZhang/OJ | usx/special/60/6034.c | <filename>usx/special/60/6034.c
#include <stdio.h>
#include <string.h>
int main () {
char n[7], s, i;
while (~scanf ("%s", n)) {
s = strlen (n);
printf ("%d", s);
for (i = 0; i < s; i++) {
printf (" %c", n[i]);
}
printf (" ");
for (i = s-1; i >= 0; i--) {
printf ("%c",n[i]);
}
printf ("\n");
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6057.c | #include <stdio.h>
#include <string.h>
int isAEIOU (char ch) {
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
return 1;
else
return 0;
}
int main () {
char src [100];
char dst [100];
while (gets (src) != NULL) {
int i, j = 0, size = strlen (src);
for (i = 0; i < size; i++) {
if (isAEIOU (src[i])) {
dst[j++] = src [i];
}
}
dst[j] = '\0';
puts (dst);
}
} |
TheBadZhang/OJ | usx/special/60/6011.c | #include <stdio.h>
int gcd (int a, int b) {
return b?gcd(b,a%b):a;
}
// int gcd (int a, int b) {
// while (b^=a^=b^=a%=b);
// return x;
// }
int main() {
int m, n;
while (~scanf("%d %d", &m, &n)) {
printf ("%d\n", gcd(m, n));
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6028.c | #include <stdio.h>
int main () {
int n, N[22]={1}, i;
for (i = 1; i <= 22; i++) {
N[i] = (N[i-1]+1)*2;
}
while (~scanf("%d", &n)) {
printf ("%d\n", N[n-1]);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6039.c | #include <stdio.h>
int josephus (int n, int m) {
if (n == 1) {
return 0;
} else {
return (josephus (n-1,m) + m)%n;
}
}
int main () {
int n, m, i, s = 0;
while(~scanf ("%d", &n)) {
printf ("%d\n", josephus (n,3)+1);
}
} |
TheBadZhang/OJ | usx/special/92/9224.c | <reponame>TheBadZhang/OJ
#include <stdio.h>
int main () {
int T, m, n, i, mini;
scanf ("%d", &T);
while (T--) {
scanf ("%d %d %d", &m, &n, &i);
printf ("%d %d\n", n+i*m, i);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6012.c | <reponame>TheBadZhang/OJ
#include <stdio.h>
#include <math.h>
// #define min(a,b) (a<b?a:b)
// #define max(a,b) (a<b?b:a)
float min (float a, float b) {
return a > b ? b : a;
}
float max (float a, float b) {
return a < b ? b : a;
}
int main () {
float a, b, c, d, e;
while (~scanf("%f%f%f%f%f", &a, &b, &c, &d, &e)) {
printf ("%.6f %.6f\n",
max(a,max(b,max(c,max(d,e)))),
min(a,min(b,min(c,min(d,e))))
);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6019.c | <gh_stars>1-10
#include <stdio.h>
int main () {
int d, z, x;
for (d = 0; d <= 100/3; d ++) {
for (z = 0; z <= (100-3*d)/2; z ++) {
for (x = 0; x <= 2*(100-3*d-2*z); x += 2) {
if (3*d + 2*z + x/2 == 100 && 100 == d + z + x) {
printf ("%d %d %d\n", d, z, x);
}
}
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6023.c | #include <stdio.h>
int main () {
int n, a, i, s, aa;
while (~scanf ("%d %d", &n, &a)) {
s = 0;
aa = 0;
for (i=0; i < n; i++) {
aa = aa*10+a;
s += aa;
}
printf ("%d\n", s);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6038.c | #include <stdio.h>
int list [400]; // 放在全局变量可以自动初始化为 0
int main () {
int i, j, k;
for (i = 1, j = 2; i < 250; i += j, j++) {
list [i] = 1; list [i-1] = 1; // 将杨辉三角的两边的 1 初始化
for (k = i + 1; k < i+j; k++) {
list [k] = list[k-j] + list[k-j+1];
// 计算杨辉三角
}
}
while (~scanf("%d", &i)) {
for (j = 0; j < i; j ++) {
if (j) printf (" ");
printf ("%d", list [j]); // 输出单行杨辉三角
}
printf ("\n");
}
return 0;
}
|
TheBadZhang/OJ | usx/special/60/6074.c | #include <stdio.h>
int main () {
int m, n, i, j;
int maxi, maxj;
int v [22][22];
while (~scanf ("%d %d", &m, &n)) {
maxi = maxj = 0;
for (i = 0; i < m; i ++) {
for (j = 0; j < n; j ++) {
scanf ("%d", &v[i][j]);
if (v[i][j] > v[maxi][maxj]) {
maxi = i;
maxj = j;
}
}
}
printf ("%d %d %d\n", maxi+1, maxj+1, v[maxi][maxj]);
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6064.c | #include <stdio.h>
int ack (int m, int n) {
if (m == 0) return n+1;
else if (n == 0) return ack(m-1, 1);
else return ack (m-1, ack(m, n-1));
}
int main () {
int m, n;
while (~scanf ("%d%d", &m, &n)) {
printf ("%d\n", ack (m, n));
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6032-2.c | <gh_stars>1-10
#include <stdio.h>
#include <math.h>
int main () {
int n, i, j;
while (~scanf ("%d", &n)) {
for (i = 0; i < 2*n-1; printf ("\n"),i++) {
for (j = 0; j++ < 2*abs((n-i-1)); printf (" "));
for (printf ("*"),j = 0; j++ < 2*(n-1-abs(n-1-i)); printf (" *"));
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6084.c | <filename>usx/special/60/6084.c
#include <string.h>
#include <stdio.h>
int main () {
int n, m, k;
int stu[12][10];
while (~scanf ("%d %d %d", &n, &m, &k)) {
int i, j, flag, flag2 = 0, flag3, flag4 = 0, sum = 0, sum2;
double average;
for (i = 0; i < n; i++) {\
for (j = 0; j < m; j++) {
scanf ("%d", &stu[i][j]);
if (j == k-1) {
sum += stu[i][j];
}
}
}
printf ("%d\n", sum/n);
for (i = 0; i < n; i++) {
sum2 = flag3 = flag = 0;
average = 0.0;
for (j = 0; j < m; j++) {
if (stu[i][j] < 60)
flag ++;
sum2 += stu[i][j];
}
if (flag >= 2) {
flag2 ++;
printf ("bad:%d", i+1);
for (j = 0; j < m; j++) {
printf (" %d", stu[i][j]);
}
printf (" %d", sum2/m);
printf ("\n");
}
}
if (flag2 == 0) {
printf ("NO\n");
}
for (i = 0; i < n; i++) {
flag3 = flag = 0;
average = 0.0;
for (j = 0; j < m; j++) {
if (stu[i][j] > 85) {
flag3 ++;
}
average += stu[i][j];
}
if (average/(double)m >= 90 || flag3 == m) {
flag4 ++;
printf ("good:%d", i+1);
for (j = 0; j < m; j++) {
printf (" %d", stu[i][j]);
}
printf ("\n");
}
}
if (flag4 == 0) {
printf ("NO\n");
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/92/9214.c | <gh_stars>1-10
#include <stdio.h>
int main () {
int a, b;
char o;
while (~scanf ("%d %d\n%c", &a, &b, &o)) {
switch (o) {
case '+': printf ("%d+%d=%d\n", a, b, a+b); break;
case '-': printf ("%d-%d=%d\n", a, b, a-b); break;
case '*': printf ("%d*%d=%d\n", a, b, a*b); break;
case '/': printf ("%d/%d=%.2f\n", a, b, (double)a/(double)b); break;
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6088-2.c | #include <stdio.h>
int main () {
int n, i;
char name[80];
double value;
while (~scanf ("%d\n", &n)) {
for (i = 0; i < n; i++) {
scanf ("%s %lf", name, &value);
printf ("%s %.2lf\n", name, value);
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6040.c | <gh_stars>1-10
#include <stdio.h>
#include <math.h>
int isPrime (int n) {
int i;
for (i = 3; i <= sqrt (n); i++) {
if (n % i == 0) return 0;
}
return 1;
}
int main () {
int n, i = 2;
int sushu[300] = { 2, 3 };
for (n = 1; n < 40; n ++) {
if (isPrime (n*6-1)) sushu[i++] = n*6-1;
if (isPrime (n*6+1)) sushu [i++] = n*6+1;
}
while (~scanf ("%d", &n)) {
i = 1;
if (n>=2) {
printf ("2");
}
while (sushu[i++] <= n) {
printf (" %d", sushu[i-1]);
}
printf ("\n");
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6068.c | #include <stdio.h>
#include <math.h>
int N;
double f (int n, double x, double z) {
double y;
if (n >= N) return 0.0;
if (n > 0) z = z * x * x / (2*n) / (2*n+1);
else z = x;
if (n&1) {
y = -z+f(n+1, x, z);
} else {
y = z+f(n+1, x, z);
}
// printf ("%d %lf %lf %lf\n", n, x, z, y);
return y;
}
int main () {
double x;
while (~scanf ("%d %lf", &N, &x)) {
printf ("%.3lf\n", f(0,x,1.0));
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6036.c | #include <stdio.h>
int main () {
int fibo [50] = { 1, 1, 2, 3 };
int i;
for (i = 2; i < 50; i++) {
fibo [i] = fibo [i-1] + fibo [i-2];
}
int n;
while (~scanf ("%d", &n)) {
for (i = 1; i <= n; i++) {
// if (i%5 != 1) printf (" ");
if (i%5!=1) printf (" ");
printf ("%d", fibo [i-1]);
if (i%5 == 0) printf ("\n");
}
if (n%5)
printf ("\n");
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6013.c | <filename>usx/special/60/6013.c
#include <stdio.h>
int main () {
int year;
while (~scanf("%d", &year)) {
if (year % 100 == 0 && year % 400 == 0 ||
year % 100 != 0 && year % 4 == 0) {
printf ("is LEAP!\n");
} else {
printf ("is NOT LEAP!\n");
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/91/9118-2.c | <reponame>TheBadZhang/OJ
#include <stdio.h>
int main () {
puts("CD");
return 0;
} |
TheBadZhang/OJ | usx/special/60/6075.c | <filename>usx/special/60/6075.c
#include <stdio.h>
int main () {
int n, m;
int s[20][20];
int a, b;
while (~scanf("%d%d", &a, &b)) {
for (n = 0; n < a; n++) {
for (m = 0; m < b; m++) {
scanf ("%d", &s[n][m]);
}
}
for (n = 0; n < a; n++) {
int flag = 0;
for (m = 0; m < b; m++) {
if (s[n][m] < 60.0) {
flag = 1;
}
}
if (flag) {
printf ("%d", n);
for (m = 0; m < b; m++) {
printf (" %d", s[n][m]);
}
printf ("\n");
}
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6041.c | <reponame>TheBadZhang/OJ
#include <stdio.h>
#include <stdlib.h>
int comp(const void* a, const void* b) {
return *(int*)a - *(int*)b;
}
void swap (int* a, int* b) {
int c = *a;
*a = *b;
*b = c;
}
void bubbleSort (int* list, int size) {
int i, j;
for (i = 0; i < size; i ++) {
for (j = i+1; j < size; j++) {
if (list[i] > list[j]) { // 大的数字向上冒
swap (&list[i], &list[j]);
/* int t = list[i];
** list [i] = list [j];
** list [j] = t;
*/
}
}
}
}
int main () {
int i, n, a[50];
while (~scanf ("%d", &n)) {
for (i = 0; i < n; i++) {
scanf ("%d", &a[i]);
}
// qsort (a, n, sizeof(int), comp);
bubbleSort (a, n);
printf ("%d", a[0]);
for (i = 1; i < n; i++) {
printf (" %d", a[i]);
}
printf ("\n");
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6066.c | #include <stdio.h>
double P (double x, int n) {
if (n == 0) return 1.0;
else if (n == 1) return x;
else if (n > 1) return ((2*n-1)*x-P(x,n-1)-(n-1)*P(x,n-2))/(double)n;
}
int main () {
double x;
int n;
while (~scanf ("%d %lf", &n, &x)) {
printf ("%.6lf\n", P(x,n));
}
return 0;
} |
TheBadZhang/OJ | usx/special/92/9217.c | #include <stdio.h>
int main () {
char str[1024];
int i;
while (~scanf ("%s", str)) {
i = 0;
while (str[i++]);
printf ("%d\n", i-1);
}
} |
TheBadZhang/OJ | usx/special/60/6059.c | #include <stdio.h>
#include <string.h>
#include <ctype.h>
int main () {
char str[100];
while (gets(str) != NULL) {
int count [128] = {0};
int i, j = 0;
for (i = 0; i < strlen (str); i++) {
if (isalpha (str[i])) {
count [str[i]] ++;
}
}
int counts = 0;
for (i = 0; i < 128; i ++) {
if (count[i] != 0) {
if (counts%10) printf (" ");
else if (counts!=0) printf ("\n");
printf ("%c--%d", i, count[i]);
counts ++;
}
}
printf ("\n");
}
return 0;
} |
TheBadZhang/OJ | usx/special/92/9207.c | #include <stdio.h>
int main () {
float a;
while (~scanf ("%f", &a)) {
if (a <= 50.0) {
printf ("%.2f\n", a*0.15);
} else {
printf ("%.2f\n", 7.5+(a-50)*0.25);
}
}
return 0;
} |
TheBadZhang/OJ | usx/special/60/6085.c | <gh_stars>1-10
#include <stdio.h>
#include <math.h>
#include <string.h>
void output(char *s, int n); //声明输出函数
int main() {
char str[300] = {0};
while (gets (str) != NULL) {
output (str, strlen (str)+1); //调用输出函数
}
return 0;
}
//输出函数
void output(char *s, int n) {
char *i;
int j, k, t, m, temp[10], num;
double sum, a[30];
for (i=s, num=0, j=0, m=0; i<s+n; i++) {
if (*i>='0'&&*i<='9')
num=1, temp[j++]=(int)(*i-'0');
else if (num) {
for (num=0, k=0, sum=0, t=j-1; k<j; sum+=temp[k]*pow(10, t), t--, k++);
a[m++]=sum, j=0;
}
}
printf ("%d", m);
for(j=0; j<m; printf(" %.0f", a[j++]));
printf("\n");
} |
TheBadZhang/OJ | usx/special/60/6024.c | #include <stdio.h>
int main () {
int n, i;
double s;
while (~scanf ("%d", &n)) {
s = 0.0;
for (i = 1; i <= n; ++i) {
s += (double)i;
s += (double)i*(double)i;
s += 1.0/(double)i;
}
printf ("%.6lf\n", s);
}
return 0;
} |
TheBadZhang/OJ | leetcode/0000/1-500/461.c | <reponame>TheBadZhang/OJ<filename>leetcode/0000/1-500/461.c
int hammingDistance(int x, int y){
int max = x > y ? x : y;
int min = x > y ? y : x;
int count = 0;
while (max > 0) {
if (max & 1 ^ min & 1) count ++;
// printf ("%d %d\n", max, min);
max >>= 1;
min >>= 1;
}
return count;
} |
TheBadZhang/OJ | usx/special/60/6021.c | <filename>usx/special/60/6021.c
#include <stdio.h>
int main () {
int i = 0;
while (i++, !(i%2==1 && i%3==2 && i%5==4 && i%6==5 && i%7==0));
printf ("%d", i);
return 0;
} |
TheBadZhang/OJ | usx/special/60/6086.c | <reponame>TheBadZhang/OJ
#include <stdio.h>
struct STU {
int num;
char name[20];
char sex;
int age;
int score [3];
};
int main () {
struct STU stu[10];
int n, i;
while (~scanf ("%d", &n)) {
for (i = 0; i < n; i ++) {
scanf ("%d %s\n%c%d%d%d%d",
&stu[i].num, stu[i].name,
&stu[i].sex, &stu[i].age,
&stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
int sum = stu[i].score[0] + stu[i].score[1] + stu[i].score[2];
printf ("%d %s %c %d %d %d %d %d %d\n",
stu[i].num, stu[i].name, stu[i].sex,
stu[i].age, stu[i].score[0], stu[i].score[1], stu[i].score[2], sum, sum/3);
}
}
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.