コード例 #1
0
ファイル: bomber.c プロジェクト: Crayon277/routine
int main(){
	char map[MARGIN_X][MARGIN_Y] = {
		"#############",
		"#GG.GGG#GGG.#",
		"###.#G#G#G#G#",
		"#.......#..G#",
		"#G#.###.#G#G#",
		"#GG.GGG.#.GG#",
		"#G#.#G#.#.#.#",
		"##G...G.....#",
		"#G#.#G###.#G#",
		"#...G#GGG.GG#",
		"#G#.#G#G#.#G#",
		"#GG.GGG#G.GG#",
		"#############"
		
	};
	int max,m_x,m_y;
	
	m_x = 3;
	m_y = 3;
	max = statistic(3,3,map);
	book[3][3] = 1;
	dfs_bomber(3,3,&max,&m_x,&m_y,map);
	
	printf("(%d,%d) max is %d\n",m_x,m_y,max);

	return 0;
}
コード例 #2
0
ファイル: homework-8.c プロジェクト: evelinesl/myNCCL
int main(void)
{
	int number1, number2;

	printf("Please input two integer numbers: ");
	scanf("%d  %d", &number1, &number2);

	printf("The number of the same digits between %d and %d is %d\n",number1, number2, statistic(number1,number2));

	return 0;
}
コード例 #3
0
ファイル: ringbuffer.cpp プロジェクト: mildrock/dummy
void RingBuffer::skip(int len)
{
	m_head += len;

	if (m_head >= m_size) {
		m_head = 0;

		LOG_WARN << "restart";
		statistic();
		exit(0);
	}
}
コード例 #4
0
ファイル: pcap.cpp プロジェクト: dycforever/netlib
bool PcapParser::Parse(const std::string& dataFile)
{
    char errbuf[PCAP_ERRBUF_SIZE]={0};
    pcap_t* handler = NULL;
    const u_char* data;
    struct pcap_pkthdr hdr;
    
    handler = pcap_open_offline(dataFile.c_str(), errbuf);
    if (handler == NULL) {
        return false;
    }
    while ((data = pcap_next(handler, &hdr)) != NULL) {            
        statistic(&hdr, data);
    }
    return true;
}
コード例 #5
0
ファイル: ringbuffer.cpp プロジェクト: mildrock/dummy
RingBufferBlock* RingBuffer::allocFreeBlock(int size)
{
	// 先从当前位置往后找起
	RingBufferBlock *block = searchFreeBlock(size);

	// 如果找不到则从头开始找
	if (NULL == block) {
		LOG_WARN << "try to find from head = 0";
		statistic();

		m_head = 0;
		block = searchFreeBlock(size);
	}

	// m_head = getBlockOffset(getNextBlock(block));
	return block;
}
コード例 #6
0
xbox_live_result<std::shared_ptr<statistic_change_subscription>>
user_statistics_service_impl::subscribe_to_statistic_change(
    _In_ const string_t& xboxUserId,
    _In_ const string_t& serviceConfigurationId,
    _In_ const string_t& statisticName
    )
{
    std::weak_ptr<user_statistics_service_impl> thisWeakPtr = shared_from_this();

    std::shared_ptr<statistic_change_subscription> statChangeSub = std::make_shared<statistic_change_subscription>(
        xboxUserId,
        serviceConfigurationId,
        statistic(
            statisticName,
            string_t(),
            string_t()
            ),
        ([thisWeakPtr](const statistic_change_event_args& eventArgs)
        {
            std::shared_ptr<user_statistics_service_impl> pThis(thisWeakPtr.lock());
            if (pThis != nullptr)
            {
                pThis->statistic_changed(eventArgs);
            }
        }),
        ([thisWeakPtr](const xbox::services::real_time_activity::real_time_activity_subscription_error_event_args& eventArgs)
        {
            std::shared_ptr<user_statistics_service_impl> pThis(thisWeakPtr.lock());
            if (pThis != nullptr)
            {
                pThis->m_realTimeActivityService->_Trigger_subscription_error(eventArgs);
            }
        })
        );

    auto subscriptionSucceeded = m_realTimeActivityService->_Add_subscription(
        statChangeSub
        );

    if (!subscriptionSucceeded.err())
    {
        return xbox_live_result<std::shared_ptr<statistic_change_subscription>>(statChangeSub);
    }

    return xbox_live_result<std::shared_ptr<statistic_change_subscription>>(subscriptionSucceeded.err(), subscriptionSucceeded.err_message());
}
コード例 #7
0
ファイル: locate.c プロジェクト: kusumi/DragonFlyBSD
static void
search_fopen(char *db, char **s)
{
	FILE *fp;
#ifdef DEBUG
        long t0;
#endif
	       
	/* can only read stdin once */
	if (f_stdin) { 
		fp = stdin;
		if (*(s+1) != NULL) {
			warnx("read database from stdin, use only `%s' as pattern", *s);
			*(s+1) = NULL;
		}
	} 
	else if ((fp = fopen(path_fcodes, "r")) == NULL)
		err(1,  "`%s'", path_fcodes);

	/* count only chars or lines */
	if (f_statistic) {
		statistic(fp, path_fcodes);
		(void)fclose(fp);
		return;
	}

	/* foreach search string ... */
	while(*s != NULL) {
#ifdef DEBUG
		t0 = cputime();
#endif
		if (!f_stdin &&
		    fseek(fp, (long)0, SEEK_SET) == -1)
			err(1, "fseek to begin of ``%s''\n", path_fcodes);

		if (f_icase)
			fastfind_icase(fp, *s, path_fcodes);
		else
			fastfind(fp, *s, path_fcodes);
#ifdef DEBUG
		warnx("fastfind %ld ms", cputime () - t0);
#endif
		s++;
	} 
	(void)fclose(fp);
} 
コード例 #8
0
    Formats::Chiptune::Container::Ptr Parse(const Binary::Container& rawData, Builder& target)
    {
      const Binary::TypedContainer data = CreateContainer(rawData);

      if (!FastCheck(data))
      {
        return Formats::Chiptune::Container::Ptr();
      }

      try
      {
        const Format format(data);

        StatisticCollectingBuilder statistic(target);
        format.ParseCommonProperties(statistic);
        format.ParsePositions(statistic);
        Indices usedPatterns = statistic.GetUsedPatterns();
        const uint_t mode = statistic.GetMode();
        if (mode != SINGLE_AY_MODE
         && !AddTSPatterns(mode, usedPatterns))
        {
          target.SetMode(SINGLE_AY_MODE);
        }
        format.ParsePatterns(usedPatterns, statistic);
        const Indices& usedSamples = statistic.GetUsedSamples();
        format.ParseSamples(usedSamples, target);
        const Indices& usedOrnaments = statistic.GetUsedOrnaments();
        format.ParseOrnaments(usedOrnaments, target);

        Require(format.GetSize() >= MIN_SIZE);
        const Binary::Container::Ptr subData = rawData.GetSubcontainer(0, format.GetSize());
        const RangeChecker::Range fixedRange = format.GetFixedArea();
        return CreateCalculatingCrcContainer(subData, fixedRange.first, fixedRange.second - fixedRange.first);
      }
      catch (const std::exception&)
      {
        Dbg("Failed to create");
        return Formats::Chiptune::Container::Ptr();
      }
    }
コード例 #9
0
ファイル: bomber.c プロジェクト: Crayon277/routine
void dfs_bomber(int x, int y, int* max,int* m_x, int* m_y,char **map){
	int next[4][2] = {
		{
			0,1
		},
		{
			1,0
		},
		{
			0,-1
		},
		{
			-1,0
		}
	};
	int k,
		N_x,
		N_y,
		sum;
	sum = statistic(x,y,map);
	
	if(sum > (*max)){
		*max = sum;
		*m_x = x;
		*m_y = y;
	}

	for(k = 0 ; k<=3 ;k++){
		N_x = x + next[k][0];
		N_y = y + next[k][1];
		
		if(N_x < 0 || N_y < 0 || N_x > MARGIN_X || N_y > MARGIN_Y){
			continue;
		}
		if(book[N_x][N_y] == 0 && map[N_x][N_y] == '.'){
			book[N_x][N_y] = 1;
			dfs_bomber(N_x,N_y,max,m_x,m_y,map);		
		}
	}
}
コード例 #10
0
int main(void){
	FILE *in = fopen( "010_test.in", "r" );
	FILE *stttc_file = fopen( "010_test.statistic", "w+" );
	FILE *HT_file = fopen( "010_test.huffman-tree", "w+" );
	FILE *HC_file = fopen( "010_test.huffman-code", "w+" );
	FILE *out = fopen( "010_test.out", "w" );

	int symbol_total = statistic( in, stttc_file );
	HuffmanTree tree = generate_HT( stttc_file, symbol_total, HT_file );
	HuffmanCode code = generate_HC( tree, symbol_total, HC_file );
	code_file( in, code, out );
	
	fclose( in );
	fclose( stttc_file );
	fclose( HT_file );
	fclose( HC_file );
	fclose( out );
	free( tree );
	free( code );

	return 0;
}
コード例 #11
0
ファイル: ringbuffer.cpp プロジェクト: mildrock/dummy
RingBufferBlock* RingBuffer::splitBlock(int sum, int size)
{
	int alignLength = ALIGN(sizeof(struct RingBufferBlock) + size);

	// 切割出第一个长度为size的block
	struct RingBufferBlock *head = getHead();
	head->m_length = size;
	head->m_skip = 0;
	head->m_next = NULL;
	head->m_link = NULL;

	// 切割出第二个长度为sum - size的block
	struct RingBufferBlock *next = getNextBlock(head);
	if (next) {
		int nextOffset = getBlockOffset(next);

		// 如果第二块位于末尾,判断空间是否足够再构造一个block
		if (m_size - nextOffset > sizeof(RingBufferBlock)) {
			if (alignLength < sum) {
				next->m_length = sum - alignLength - sizeof(RingBufferBlock);
				next->m_link = NULL;
				next->m_next = NULL;
				next->m_skip = 0;

				if (next->m_length <= 0) {
					LOG_ERROR << "next->m_length = " << next->m_length;
					statistic();
				}
			}
		}
	} else {
		// m_head = 0;
	}

	// 返回第一块block
	return head;
}
コード例 #12
0
ファイル: csmesemma.cpp プロジェクト: testcocoon/testcocoon
QString CSMesEmma::exportEMMAStatistic(const QString &filename,int coverage_level,Instrumentation::coverage_method_t method) const
{
  const ExecutionNames executions=selectedExecutions();
  int nb_executions=executions.count();
  if (nb_executions==0)
    return QObject::tr("No executions selected");

  QFile f;
  f.setFileName(filename);
  if (f.open(QFile::WriteOnly))
  {
    bool is_test_count_mode_selected=isTestCountModeSelected();

    CSMesInstrumentations _instrumentations ;
    copyInstrumentation(_instrumentations,instrumentations);
    selectExecutionsComparaison(_instrumentations,executions,ExecutionNames(),is_test_count_mode_selected,method,false);
    CSMesInstrumentations _instrumentations_block ;
    copyInstrumentation(_instrumentations_block,instrumentations);
    selectExecutionsComparaison(_instrumentations_block,executions,ExecutionNames(),is_test_count_mode_selected,Instrumentation::COVERAGE_BRANCH,false);
    ExecutionNames::const_iterator it_fct;
    const QList<CSMesFunctionInfo::functionskey_t> functions= Functions();
    int nb_functions=functions.count();
    QHash<CSMesFunctionInfo::functionskey_t,int> nb_tested_function_list;
    QHash<CSMesFunctionInfo::functionskey_t,int> nb_untested_function_list;
    QSet<QString> classes;
    if ( statisticFunctionsExecution(executions,coverage_level,method,nb_tested_function_list,nb_untested_function_list,_instrumentations) )
    {
      for ( QList<CSMesFunctionInfo::functionskey_t>::const_iterator itFunction=functions.begin();itFunction<functions.end();++itFunction++)
      {
        const CSMesFunctionInfo::functionskey_t &f=*itFunction;
        if (nb_tested_function_list.contains(f) && nb_untested_function_list.contains(f) )
        {
          const QString &func=f.method.getScopedName();
          classes+=classFromFunction(func);
        }
      }
    }
    int nb_class=classes.count();

    QHash<ExecutionName,int> nb_tested_source_list;
    QHash<ExecutionName,int> nb_untested_source_list;
    const SourceFiles sources= Sources(NON_EMPTY);
    int nb_sources=sources.count();
    statisticSourcesExecution(sources,executions,coverage_level,method,nb_tested_source_list,nb_untested_source_list,_instrumentations) ;

    int nb_tested,nb_untested;
    statistic(coverage_level,method,nb_tested,nb_untested,_instrumentations) ;

    int nb_tested_block,nb_untested_block;
    statistic(coverage_level,Instrumentation::COVERAGE_BRANCH,nb_tested_block,nb_untested_block,_instrumentations_block) ;

    QHash<ExecutionName,int> nb_tested_source_block_list;
    QHash<ExecutionName,int> nb_untested_source_block_list;
    statisticSourcesExecution(sources,executions,coverage_level,Instrumentation::COVERAGE_BRANCH,nb_tested_source_block_list,nb_untested_source_block_list,_instrumentations_block) ;

    QHash<CSMesFunctionInfo::functionskey_t,int> nb_tested_function_block_list;
    QHash<CSMesFunctionInfo::functionskey_t,int> nb_untested_function_block_list;
    statisticFunctionsExecution(executions,coverage_level,Instrumentation::COVERAGE_BRANCH,nb_tested_function_block_list,nb_untested_function_block_list,_instrumentations_block) ;

    int nb_instrumentation=0;
    for (CSMesInstrumentations::Modules::const_iterator mod_it=_instrumentations.modules.begin();mod_it!=_instrumentations.modules.end();++mod_it)
      nb_instrumentation += mod_it->nb_measurements_items;


    QXmlStreamWriter stream(&f);
    stream.setAutoFormatting(true);
    stream.writeStartDocument();
    stream.writeStartElement("report");

    stream.writeStartElement("stats");

    stream.writeEmptyElement("packages");
    stream.writeAttribute("value",QString::number(1));

    stream.writeEmptyElement("methods");
    stream.writeAttribute("value",QString::number(nb_functions));

    stream.writeEmptyElement("srcfiles");
    stream.writeAttribute("value",QString::number(nb_sources));

    stream.writeEmptyElement("srclines");
    stream.writeAttribute("value",QString::number(nb_tested+nb_untested));

    stream.writeEmptyElement("classes");
    stream.writeAttribute("value",QString::number(nb_class));
    stream.writeEndElement();

    stream.writeStartElement("data");
    stream.writeStartElement("all");
    stream.writeAttribute("name","all classes");

    {
      int nb_tested_line=nb_tested;
      int nb_untested_line=nb_untested;
      int nb_tested_method;
      int nb_untested_method;
      int nb_tested_class;
      int nb_untested_class;
      int nb_tested_blocks=nb_tested_block;
      int nb_untested_blocks=nb_untested_block;
      emmaStatisticMethods(nb_tested_function_list,nb_tested_method,nb_untested_method);
      emmaStatisticClasses(nb_tested_function_list,nb_tested_class,nb_untested_class);

      exportEmmaStatistics(stream,nb_tested_line,nb_untested_line,nb_tested_method,nb_untested_method,nb_tested_class,nb_untested_class,nb_tested_blocks,nb_untested_blocks);
    }
    stream.writeStartElement("packages");
    stream.writeAttribute("name",getFilename());

    for (SourceFiles::const_iterator itSrc=sources.begin();itSrc!=sources.end();++itSrc)
    {
      stream.writeStartElement("srcfile");
      stream.writeAttribute("name",*itSrc);
      QList<CSMesFunctionInfo::functionskey_t> functions_source;
      QSet<QString> classes_source;
      for (QList<CSMesFunctionInfo::functionskey_t>::const_iterator itMeth=functions.begin();itMeth!=functions.end();++itMeth)
      {
        if ((*itMeth).source==*itSrc)
        {
          functions_source+=*itMeth;
          const QString &func=(*itMeth).method.getScopedName();
          classes_source+=classFromFunction(func);
        }
      }
      {
        int nb_tested_line=0;
        int nb_untested_line=0;
        if (nb_tested_source_list.contains(*itSrc) && nb_untested_source_list.contains(*itSrc) )
        {
          nb_tested_line=nb_tested_source_list[*itSrc];
          nb_untested_line=nb_untested_source_list[*itSrc];
        }
        QHash<CSMesFunctionInfo::functionskey_t,int> nb_tested_functions;
        for (QHash<CSMesFunctionInfo::functionskey_t,int>::const_iterator itFunc=nb_tested_function_list.begin();itFunc!=nb_tested_function_list.end();++itFunc)
        {
          if (itFunc.key().source==*itSrc)
            nb_tested_functions[itFunc.key()]=itFunc.value();
        }
        int nb_tested_method=0;
        int nb_untested_method=0;
        int nb_tested_class=0;
        int nb_untested_class=0;
        int nb_tested_blocks=0;
        int nb_untested_blocks=0;
        if (nb_tested_source_block_list.contains(*itSrc) && nb_untested_source_block_list.contains(*itSrc) )
        {
          nb_tested_blocks=nb_tested_source_block_list[*itSrc];
          nb_untested_blocks=nb_untested_source_block_list[*itSrc];
        }
        emmaStatisticMethods(nb_tested_functions,nb_tested_method,nb_untested_method);
        emmaStatisticClasses(nb_tested_functions,nb_tested_class,nb_untested_class);

        exportEmmaStatistics(stream,nb_tested_line,nb_untested_line,nb_tested_method,nb_untested_method,nb_tested_class,nb_untested_class,nb_tested_blocks,nb_untested_blocks);
      }
      for (QSet<QString>::const_iterator itClass=classes_source.begin();itClass!=classes_source.end();++itClass)
      {
        stream.writeStartElement("class");
        stream.writeAttribute("name",*itClass);
        {
          int nb_tested_line=0;
          int nb_untested_line=0;
          int nb_tested_blocks=0;
          int nb_untested_blocks=0;
          QHash<CSMesFunctionInfo::functionskey_t,int> nb_tested_functions;
          for (QHash<CSMesFunctionInfo::functionskey_t,int>::const_iterator itFunc=nb_tested_function_list.begin();itFunc!=nb_tested_function_list.end();++itFunc)
          {
            if ( (itFunc.key().source==*itSrc) && (classFromFunction(itFunc.key().method.getScopedName())==*itClass))
            {
              nb_tested_functions[itFunc.key()]=itFunc.value();
              nb_tested_line+=itFunc.value();
              nb_untested_line+=nb_untested_function_list[itFunc.key()];
              nb_tested_blocks+=nb_tested_function_block_list[itFunc.key()];
              nb_untested_blocks+=nb_untested_function_block_list[itFunc.key()];
            }
          }
          int nb_tested_method=0;
          int nb_untested_method=0;
          int nb_tested_class=0;
          int nb_untested_class=0;
          emmaStatisticMethods(nb_tested_functions,nb_tested_method,nb_untested_method);
          emmaStatisticClasses(nb_tested_functions,nb_tested_class,nb_untested_class);

          exportEmmaStatistics(stream,nb_tested_line,nb_untested_line,nb_tested_method,nb_untested_method,nb_tested_class,nb_untested_class,nb_tested_blocks,nb_untested_blocks);
        }
        for (QList<CSMesFunctionInfo::functionskey_t>::const_iterator itMeth=functions_source.begin();itMeth!=functions_source.end();++itMeth)
        {
          if ( classFromFunction(itMeth->method.getScopedName())==*itClass)
          {
            stream.writeStartElement("method");
            stream.writeAttribute("name",(*itMeth).method.getScopedName());
            {
              int nb_tested_line=0;
              int nb_untested_line=0;
              int nb_tested_blocks=0;
              int nb_untested_blocks=0;
              QHash<CSMesFunctionInfo::functionskey_t,int> nb_tested_functions;
              for (QHash<CSMesFunctionInfo::functionskey_t,int>::const_iterator itFunc=nb_tested_function_list.begin();itFunc!=nb_tested_function_list.end();++itFunc)
              {
                if ( itFunc.key()==*itMeth )
                {
                  nb_tested_functions[itFunc.key()]=itFunc.value();
                  nb_tested_line+=itFunc.value();
                  nb_untested_line+=nb_untested_function_list[itFunc.key()];
                  nb_tested_blocks+=nb_tested_function_block_list[itFunc.key()];
                  nb_untested_blocks+=nb_untested_function_block_list[itFunc.key()];
                }
              }
              int nb_tested_method=0;
              int nb_untested_method=0;
              emmaStatisticMethods(nb_tested_functions,nb_tested_method,nb_untested_method);

              exportEmmaStatistics(stream,nb_tested_line,nb_untested_line,nb_tested_method,nb_untested_method,-1,-1,nb_tested_blocks,nb_untested_blocks);
            }
            stream.writeEndElement();
          }
        }
        stream.writeEndElement();
      }
      stream.writeEndElement();
    }

    stream.writeEndElement();
    stream.writeEndElement();
    stream.writeEndElement();
    stream.writeEndDocument();
    f.close();
    return QString();
  }
  else
    return QObject::tr("Error opening file '%1':%2").arg(filename).arg(f.errorString());
}
コード例 #13
0
/**
 * A convenience method for implementing statistics for both evaluation and
 * endowment function. It assumes that the statistic can be calculated by
 * iterating over ties (i,j) of a network Y and summing up some terms
 * s_{ij}(X) with respect to another network X, namely,
 * s(X,Y) = sum_{(i,j) \in Y} s_{ij}(X).
 * For evaluation function, X = Y.
 * For endowment function, X is the initial network of the period, and Y is the
 * network of ties that have been lost during the network evolution.
 */
double NetworkEffect::statistic(const Network * pSummationTieNetwork)
{
	return statistic(pSummationTieNetwork, false).first;
}