Esempio n. 1
0
File: main.c Progetto: RoyYuan/C-
int main()
{
int i;
system("COLOR 3B");
printf ("\n\t【2048】控制台版\n\n");
printf ("游戏规则(如同名手游):\n");
printf ("\t开始方格内会出现2或者4等这两个小数字,\n");
printf ("\t玩家只需要上下左右(方向键控制)其中一个方向来移动出现的数字,\n");
printf ("\t所有的数字就会向滑动的方向靠拢,\n");
printf ("\t而滑出的空白方块就会随机出现一个数字,\n");
printf ("\t相同的数字相撞时会叠加靠拢,\n");
printf ("\t然后一直这样,不断的叠加最终拼凑出2048这个数字就算成功。\n");
printf ("\n\n!输入任意非零字符开始游戏!\n(建议将控制台设置为大字体)\n");
char s[100];
while (scanf ("%s",s),strcmp(s,"0"))
{
memset (MAP,0,sizeof (MAP));
gre = 0;
system("CLS");
add(0);
pri();
while (mov())
{
fflush(stdin);
system("CLS");
pri();
if (pd())
break;
}
printf ("按任继续游戏!输入0退出程序!\n");
}
return 0
Esempio n. 2
0
int main(int argc,char** argv)
{
	printf("Before:\n");
	pri(arr);
	HeapSort(arr,len);
	printf("After:\n");
	pri(arr);
	return 0;
}
Esempio n. 3
0
int main(int argc,char** argv)
{
	printf("Before:\n");
	pri(arr);
	printf("after:\n");
	sort(arr);
	pri(arr);
	return 0;
}
Esempio n. 4
0
File: 5.c Progetto: guozesheng/test
void main()
{
    void pri(int *pa, int n);
    void inv(int *pa, int n);

    int a[10] = {3, 6, 7, 9, 5, 4, 2, 1, 4, 7};
    
    pri(a, 10);
    inv(a, 10);
    pri(a, 10);
}
Esempio n. 5
0
File: list.c Progetto: treblih/omfc
int
main ( int argc, char *argv[] )
{
	$pri(List) list = (PTR) gnew(List);
	$do(list, add, $arg(2));
	$do(list, add, $arg(6));
	$do(list, add, $arg(61));
	/* $do(list, rem); */

	T x = $do(($pri(Node))$do(list, find_first_nonnull), getter_x);
	
	printf("%d\n", x);
	return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
Esempio n. 6
0
/* (17) TERM      ::=  TERM  /  PRI   */
int term()
{
    int w;
    if(test&2) printf("Enter term--this=%d  next=%d\n", this, next);
    if(!pri()) return F;
    reduce(15);
    while((w = this)==TIMES || w==DIVIDE) {
        step();  /* past TIMES or DIVIDE */
        if(!pri()) return F;
        if(w==TIMES) reduce(16);
        else reduce(17);
    } 
    if(test&2) printf("Leave term\n");
    return T;
}
const Error *Amp::RequestStatUpdt( void )
{
   // For secondary axis objects, do this through the primary axis
   if( primaryAmpRef )
   {
      RefObjLocker<Amp> pri( primaryAmpRef );
      if( !pri ) return &AmpError::NotInit;
      return pri->RequestStatUpdt();
   }

   // Note that 8367 based products don't support remote 
   // requests well, so we use an SDO to request the PDO
   if( (hwType & 0xFF00) != 0x0300 )
   {
      RefObjLocker<Network> net( GetNetworkRef() );
      if( !net ) return &NodeError::NetworkUnavailable;

      if( !statPDO ) 
         return &AmpError::NotInit;

      return statPDO->Request(*net);
   }
   else
      return Dnld8( OBJID_PDOREQUEST, 0, (uint8)0 );
}
Esempio n. 8
0
void PriGenerator::generate()
{
    QHashIterator<QString, Pri> pri(priHash);
    while (pri.hasNext()) {
        pri.next();
        QStringList list = pri.value().headers;
        if (list.isEmpty())
            continue;

        QString folder = pri.key();
        FileOut file(m_out_dir + "/generated_cpp/" + folder + "/" + folder + ".pri");
        file.stream << "HEADERS += \\\n";
        qSort(list.begin(), list.end());
        foreach (const QString &entry, list) {
            file.stream << "           $$PWD/" << entry << " \\\n";
        }

        file.stream << "\n";
        file.stream << "SOURCES += \\\n";
        list = pri.value().sources;
        qSort(list.begin(), list.end());
        foreach (const QString &entry, list) {
            file.stream << "           $$PWD/" << entry << " \\\n";
        }
        file.stream << "           $$PWD/" << folder << "_init.cpp\n";

        if (file.done())
            ++m_num_generated_written;
        ++m_num_generated;
    }
}
Esempio n. 9
0
int main(){
    peca proxima_peca, peca_atual;
    int i,j;

    proxima_peca.forma[0][0]=0;
    proxima_peca.forma[0][1]=1;
    proxima_peca.forma[0][2]=0;
    proxima_peca.forma[0][3]=0;
    proxima_peca.forma[1][0]=0;
    proxima_peca.forma[1][1]=1;
    proxima_peca.forma[1][2]=1;
    proxima_peca.forma[1][3]=0;
    proxima_peca.forma[2][0]=0;
    proxima_peca.forma[2][1]=1;
    proxima_peca.forma[2][2]=0;
    proxima_peca.forma[2][3]=0;
    proxima_peca.forma[3][0]=0;
    proxima_peca.forma[3][1]=0;
    proxima_peca.forma[3][2]=0;
    proxima_peca.forma[3][3]=0;

    peca_atual = gerar(peca_atual);
    printf("peca atual \n");
    pri(peca_atual);
/*    printf("\n proxima peca\n");
    pri(proxima_peca); //ok
    proxima_peca = girar(proxima_peca);
    printf("\n peca girada\n");
    pri(proxima_peca);
    //proxima_peca = girar(proxima_peca);
    //pri(proxima_peca);
*/
    return 0;
}
Esempio n. 10
0
File: point.c Progetto: treblih/omfc
int
main(int argc, char *argv[])
{
	$pri(Point) point = (PTR) gnew(Point, 5, 6);
	$do(point, draw);
	return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
Esempio n. 11
0
bool hashheap<T>::remove(std::string key)
    {
    size_t hashIndex = hashFunction(key);
    pair<std::string, T> p(key);
    priorityContainer<pair<std::string, T> > pri(p);
    return dictionary[hashIndex].remove(pri, &contentEquality);
    }
Esempio n. 12
0
File: stack.c Progetto: treblih/omfc
	int
main ( int argc, char *argv[] )
{
	$pri(Stack) stk = (PTR) gnew(Stack);
	$do(stk, push, $arg(5));
	printf("%d\n", $do(stk, pop));

	return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
Esempio n. 13
0
bool hashheap<T>::search(std::string key, T& data) const
    {
    size_t hashIndex = hashFunction(key);
    pair<std::string, T> p(key, data);
    priorityContainer<pair<std::string, T> > pri(p);
    bool existence = dictionary[hashIndex].exists(pri, &contentEquality);
    data = pri.getContent().getData();
    return existence;
    }
Esempio n. 14
0
int main(void)
{
	int a, b, c;

	foo(12345);
	bar(1234, abc);

	if ()
		pri(3);
	else
Esempio n. 15
0
  /**
   *  Assuming a.type is either the numerator.type or denominator.type in
   *  the price equation, return the number of the other asset type that
   *  could be exchanged at price p.
   *
   *  ie:  p = 3 usd/bts & a = 4 bts then result = 12 usd
   *  ie:  p = 3 usd/bts & a = 4 usd then result = 1.333 bts 
   */
  asset operator * ( const asset& a, const price& p )
  {
    try {
        if( a.asset_id == p.base_asset_id )
        {
            fc::bigint ba( a.amount ); // 64.64
            fc::bigint r( p.ratio ); // 64.64

            auto amnt = ba * r; //  128.128
            amnt /= BTS_PRICE_PRECISION; // 128.64 
            auto lg2 = amnt.log2();
            if( lg2 >= 128 )
            {
               FC_THROW_EXCEPTION( addition_overflow, "overflow ${a} * ${p}", ("a",a)("p",p) );
            }

            asset rtn;
            rtn.amount = amnt.to_int64();
            rtn.asset_id = p.quote_asset_id;

            ilog( "${a} * ${p} => ${rtn}", ("a", a)("p",p )("rtn",rtn) );
            return rtn;
        }
        else if( a.asset_id == p.quote_asset_id )
        {
            fc::bigint amt( a.amount ); // 64.64
            amt *= BTS_PRICE_PRECISION; //<<= 64;  // 64.128
            fc::bigint pri( p.ratio ); // 64.64

            auto result = amt / pri;  // 64.64
//            ilog( "amt: ${amt} / ${pri}", ("amt",string(amt))("pri",string(pri) ) );
 //           ilog( "${r}", ("r",string(result) ) );

            auto lg2 = result.log2();
            if( lg2 >= 128 )
            {
             //  wlog( "." );
               FC_THROW_EXCEPTION( addition_overflow, 
                                    "overflow ${a} / ${p} = ${r} lg2 = ${l}", 
                                    ("a",a)("p",p)("r", std::string(result)  )("l",lg2) );
            }
          //  result += 5000000000; // TODO: evaluate this rounding factor..
            asset r;
            r.amount    = result.to_int64();
            r.asset_id  = p.base_asset_id;
            ilog( "r.amount = ${r}", ("r",r.amount) );
            ilog( "${a} * ${p} => ${rtn}", ("a", a)("p",p )("rtn",r) );
            return r;
        }
        FC_THROW_EXCEPTION( asset_type_mismatch, "type mismatch multiplying asset ${a} by price ${p}", 
                                            ("a",a)("p",p) );
    } FC_RETHROW_EXCEPTIONS( warn, "type mismatch multiplying asset ${a} by price ${p}", 
                                        ("a",a)("p",p) );

  }
void display(struct node*n,int label,int leaf)
{	if(n==NULL)return ;
	
	if(n->start!=-1&&leaf!=0)pri(n->start,*(n->end));

	leaf=1;
	int i=0;
	for(i=0;i<27;i++)
	{	if(n->child[i]!=NULL)
		{	leaf=0;
			pri(n->start,*(n->end));
			display(n->child[i],label+edgelength(n->child[i]),leaf);
		}	
		
	}
	if(leaf==1)
	{	n->index=size-label;
		pri(n->start,*(n->end));
		printf(" [%d]\n",n->index);
	}
}
// Send a PDO to update the PVT buffer
const Error *Amp::xmitPvtPDO( uint8 val[] )
{
   if( primaryAmpRef )
   {
      RefObjLocker<Amp> pri( primaryAmpRef );
      if( pri && pri->pvtCtrlPDO )
         return pri->pvtCtrlPDO->Transmit( axisNum, val );
   }
   else if( pvtCtrlPDO )
      return pvtCtrlPDO->Transmit( 0, val );
   return 0;
}
// Send a PDO to update the control word.  Only used on EtherCAT networks.
const Error *Amp::xmitCtrlPDO( uint16 val )
{
   if( primaryAmpRef )
   {
      RefObjLocker<Amp> pri( primaryAmpRef );
      if( pri && pri->ctrlPDO )
         return pri->ctrlPDO->Transmit( axisNum, val );
   }
   else if( ctrlPDO )
      return ctrlPDO->Transmit( 0, val );
   return 0;
}
Esempio n. 19
0
T& hashheap<T>::operator [] (std::string key)
    {
    size_t hashIndex = hashFunction(key);
    pair<std::string, T> p(key);
    priorityContainer<pair<std::string, T> > pri(p);
    if (true == dictionary[hashIndex].exists(pri, &contentEquality))
        {
        return pri.getContent().getDataRef();
        }
    dictionary[hashIndex].insert(pri);
    return p.getDataRef();
    }
Esempio n. 20
0
  /**
   *  Assuming a.type is either the numerator.type or denominator.type in
   *  the price equation, return the number of the other asset type that
   *  could be exchanged at price p.
   *
   *  ie:  p = 3 usd/bts & a = 4 bts then result = 12 usd
   *  ie:  p = 3 usd/bts & a = 4 usd then result = 1.333 bts 
   */
  asset operator * ( const asset& a, const price& p )
  {
    try {
        if( a.unit == p.base_unit )
        {
            fc::bigint ba( a.amount ); // 64.64
            fc::bigint r( p.ratio ); // 64.64
            //fc::uint128 ba_test = ba; 

            auto amnt = ba * r; //  128.128
            amnt >>= 64; // 128.64 
            auto lg2 = amnt.log2();
            if( lg2 >= 128 )
            {
               FC_THROW_EXCEPTION( exception, "overflow ${a} * ${p}", ("a",a)("p",p) );
            }
         //   amnt += 5000000000; // TODO:evaluate this rounding factor... 

            asset rtn;
            rtn.amount = amnt;
            rtn.unit = p.quote_unit;

            ilog( "${a} * ${p} => ${rtn}", ("a", a)("p",p )("rtn",rtn) );
            return rtn;
        }
        else if( a.unit == p.quote_unit )
        {
            fc::bigint amt( a.amount ); // 64.64
            amt <<= 64;  // 64.128
            fc::bigint pri( p.ratio ); // 64.64

            auto result = amt / pri;  // 64.64
            //auto test_result = result;
            //ilog( "test result: ${r}", ("r", std::string(test_result >>= 60) ) );
            auto lg2 = result.log2();
            if( lg2 >= 128 )
            {
             //  wlog( "." );
               FC_THROW_EXCEPTION( exception, 
                                    "overflow ${a} / ${p} = ${r} lg2 = ${l}", 
                                    ("a",a)("p",p)("r", std::string(result)  )("l",lg2) );
            }
          //  result += 5000000000; // TODO: evaluate this rounding factor..
            asset r;
            r.amount = result;
            r.unit   = p.base_unit;
            ilog( "${a} * ${p} => ${rtn}", ("a", a)("p",p )("rtn",r) );
            return r;
        }
        FC_THROW_EXCEPTION( exception, "type mismatch multiplying asset ${a} by price ${p}", 
                                            ("a",a)("p",p) );
    } FC_RETHROW_EXCEPTIONS( warn, "type mismatch multiplying asset ${a} by price ${p}", 
/// Return the most recent event status word from my PDO
EVENT_STATUS Amp::getPdoEventStat( void )
{
   EVENT_STATUS ret = (EVENT_STATUS)0;
   if( primaryAmpRef )
   {
      RefObjLocker<Amp> pri( primaryAmpRef );
      if( pri && pri->statPDO )
         ret = pri->statPDO->getPdoEventStat( axisNum );
   }
   else if( statPDO )
      ret = statPDO->getPdoEventStat(0);
   return ret;
}
Esempio n. 22
0
File: 10222.cpp Progetto: fkrafi/UVa
int main(){
	int i, l;
	gets(s);
	l = strlen(s);
	for(i=0; i<l; i++){
		if(s[i] != ' '){
			pri(s[i]);
		}else{
			printf(" ");
		}
	}
	printf("\n");
	return 0;
}
Esempio n. 23
0
// função que faz a rotação das peças
peca girar(peca ps){
    peca rodada;

    int k,i,j,temp;
    for(i=0;i<=3;i++){//Rodando a matriz
        for(j=0;j<=3;j++){
            rodada.forma[j][i]=ps.forma[3-i][j];
        }
        rodada = cumelinha(rodada); // verificando linha em branco
    }
    printf("\nrodada o/\n");
    pri(rodada);
    return rodada;
}
Esempio n. 24
0
int main()
{
    int a[]={98,76,109,34,67,190,80,12,14,89,1};
    int k=sizeof(a)/sizeof(a[0]);
    int j;
    int i=1;
    pri(a, k);

    for(;i<k;i++)
    {
        if(a[i]<a[i-1]) //第一个自成序列 从第二个开始比较
        {
            int temp=a[i];
            for(j=i-1;j>=0 && a[j]>temp;j--)//将当前和已插入并排序的进行比较 遍历比当前大的
            {
                a[j+1]=a[j];//比当前大的往后移
            }
            a[j+1]=temp;//将当前的插入正确位置
        }
	pri(a, k);
    }
    return 0;
}
/// Return the DS402 status word from my PDO
uint16 Amp::getPdoDS402Stat( void )
{
   uint16 ret = 0;

   if( primaryAmpRef )
   {
      RefObjLocker<Amp> pri( primaryAmpRef );
      if( pri && pri->statPDO )
         ret = pri->statPDO->getCanStat( axisNum );
   }
   else if( statPDO )
      ret = statPDO->getCanStat(0);
   return ret;
}
Esempio n. 26
0
// Função que reorganiza as linhas da matriz, retirando
// as linhas vazias acima, subindo as demais e zerando a última linha.
peca sobelinha(peca ps){
    int i,j;

    for(i=0;i<4;i++){
        for(j=0;j<4;j++){
            if(i==3){
                //printf("\n entrou \n");
                ps.forma[i][j]=0;
            }
            else
                ps.forma[i][j]=ps.forma[i+1][j];
        }
    }
    printf("\n Funcao sobelinha\n");
    pri(ps);
}
Esempio n. 27
0
void main()
{
clrscr();
struct customer bank[F];
int a,b,c;
printf("\n\n-------------------------------\n");
printf("\n-----------RANDOM BANK-----------\n");
printf("\nEnter your A/C number,name,balance in account\n");
for(a=0;a<F;a++)
{
printf("\n%d.USER\n",a+1);
printf("\nEnter Your Account number:\n");
scanf("%lu",&bank[a].account);
printf("\nEnter Your Name :\n");
scanf("%s",&bank[a].name);
printf("\nEnter Your Balance in Account:\n");
scanf("%ld",&bank[a].balance);
}
printf("\n\n======================================\n");
printf("\n1.Print the account number and name of each customer with balance below RS.100\n");
printf("2.Withdraw or Deposit \n");
printf("choose any one:");
scanf("%d",&b);
switch(b)
{
case 1:
{
printf("\nYou Enter 1st case\n");
pri(bank);
break;
}
case 2:
{
printf("\nYou Enter 2nd case\n");
with(bank);
break;
}
default:
{
printf("\nYou enter wrong key");
break;
}
}
getch();
}
Esempio n. 28
0
bool hashheap<T>::insert(std::string key, T data)
    {
    bool uniqueKey = false;
    size_t hashIndex = hashFunction(key);
    pair<std::string, T> p(key, data);
    priorityContainer<pair<std::string, T> > pri(p);
    if (false == dictionary[hashIndex].exists(pri, &contentEquality))
        {
        uniqueKey = true;
        dictionary[hashIndex].insert(pri);
        }
    else
        {
        // overwrite data : no change to priority (heap is good)
        pri.getContent().getDataRef() = data;
        }
    return uniqueKey;
    }
Esempio n. 29
0
File: 7.c Progetto: Chirath02/cLab
main()
{
	int a;
	printf("Enter the no :");
	scanf("%d",&a);
	if(pal(a))
	printf("The no is palindrome .\n");
	if(fiba(a))
	printf("The no is fibanocci .\n");
	if(pri(a))
	printf("The no is prime .\n");	
	if(arm(a))
	printf("The no is armstrong .\n");
	if(per(a))
	printf("The no is perfect .\n");
	
	
	return 0;
}
Esempio n. 30
0
csList<Waypoint*> psPathNetwork::FindWaypointRoute(Waypoint * start, Waypoint * end, const psPathNetwork::RouteFilter* routeFilter)
{
    csList<Waypoint*> waypoint_list;
    csList<Waypoint*> priority; // Should have been a priority queue
    csPDelArray<Waypoint>::Iterator iter(waypoints.GetIterator());
    Waypoint *wp;
    
    // Using Dijkstra's algorithm to find shortest way

    // Initialize
    while (iter.HasNext())
    {
        wp = iter.Next();

        // Filter the waypoints with exception of the start and end point.
        if ((wp != start) && (wp != end) && routeFilter->Filter(wp))
        {
            wp->excluded = true;
            continue; // No need to think more about this waypoint
        }
        else    
        {
            wp->excluded = false;
        }

        wp->distance = INFINITY_DISTANCE;
        wp->pi = NULL;
        
        // Insert WP into priority queue
        priority.PushBack(wp);
    }
    start->distance = 0;

    while (!priority.IsEmpty())
    {
        Waypoint *wp_u = NULL;
        Waypoint *pri_wp = NULL;

        // Extract min from priority queue
        csList<Waypoint*>::Iterator pri(priority);
        csList<Waypoint*>::Iterator pri_loc;
        while (pri.HasNext())
        {
            pri_wp = pri.Next();

            if (!wp_u || pri_wp->distance < wp_u->distance)
            {
                wp_u = pri_wp;
                pri_loc = pri;
            }
        }
        priority.Delete(pri_loc);
        size_t v;
        for (v = 0; v < wp_u->links.GetSize(); v++)
        {
            Waypoint * wp_v = wp_u->links[v];

            // Is the target waypoint excluded, in that case continue on.
            if (wp_v->excluded)
            {
                continue;
            }

            // Relax
            if (wp_v->distance > wp_u->distance + wp_u->dists[v])
            {
                wp_v->distance = wp_u->distance + wp_u->dists[v];
                wp_v->pi = wp_u;
            }
        }
        // if wp == end, we should be done!!!!!!
    }

    wp = end;

    if (end->pi)
    {
        wp = end;
        while (wp)
        {
            waypoint_list.PushFront(wp);
            wp = wp->pi;
        }
    }

    return waypoint_list;
}