码迷,mamicode.com
首页 > 其他好文 > 详细

【CVTE20160807】和一个全排列相关的例子

时间:2016-08-08 07:40:00      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:【cvte】

  #include<bits/stdc++.h>
using namespace std;
  char  fun(char s[])
{
    char ret=‘\0‘;
   if(s==NULL) return  ret;
   char* p=s;   char* q=s;
   while(*p!=‘\0‘)
     {
       while(*q!=‘\0‘)
          {
           ++q;
          if(*q==*p)break;
          }
       if(*q!=‘\0‘)
           {
           ret=*p;
            break;
           }
       ++p;
     }
     return ret;
}

char Find(char *str)
{
   if(str == NULL || *str == ‘\0‘)
       return ‘\0‘;
   int *p = new int[256];
   for(int i=0;i < 256;++i)
      p[i] = 0;
    
   while(*str != ‘\0‘)
   {
      p[*str]++;
      if(p[*str] == 2)
        return *str;
      ++str;
    }
    return ‘\0‘;  
}
int main()
{  
      char s[]="google";
       cout<<fun(s)<<endl;
      cout<<Find(s)<<endl;
	cout << "Hello,C++ world of AnycodeX!" << endl;
	return 0;
}
 

   #include<bits/stdc++.h>
using namespace std;
int funadd(int n)
{

int tmp=n;
if(n<0) tmp*=-1;
int ret=tmp%10; 
while(tmp>10)
{
ret+=(tmp/10)%10; 
tmp/=10; 
} 
int r=ret%10;
int f=ret/10;
  ret=f+r;
if(n<0)ret*=-1;  
return ret;
}
 vector<int> cs(  vector<int>&unsort)
{
	int n=unsort.size();
	if(n<2) return unsort;
 
     int a[n];
     int b[n];
    vector<int>::const_iterator it=unsort.begin();
    for(int i=0;it<unsort.end();++it,++i)
    {
       a[i]=funadd(*it); 
       b[i]=*it;
    }
  
//    unsort.erase(unsort.begin(),unsort.end());  cant
    for(int i=0;i<n;i++)
      {
           for(int j=i;j<n;j++)
           if(a[j]<a[i])
	   {
		swap(a[i],a[j]);
		swap(b[i],b[j]);
	   } else if(a[j] == a[i])
	   {
		if(b[j] < b[i])
		{
		    swap(a[i],a[j]);
		    swap(b[i],b[j]);
		}
	   }
      }
    
     for(int i=0;i<n;++i)
    {
        cout<<a[i]<<" ";
         
    }
   cout<<endl;
for(int i=0;i<n;++i)
    { 
        cout<<b[i]<<" ";
    }
   cout<<endl;

   vector<int> p;
   for(int i=0;i < n;++i)
   {	
	p.push_back(b[i]);
   }
cout<<&p<<endl;
   return p;
}
int main()
{  
     vector<int>qq; 
      qq.push_back(17);
      qq.push_back(71);
      qq.push_back(44);
     vector<int> s = cs(qq);
cout<<&s<<endl;
   vector<int>::iterator it;
     for(it = s.begin();it != s.end();++it)
    cout<<*it<<" ";
   cout<<endl;

               //  qq.erase(qq.begin(),qq.end());
	cout << "Hello,C++ world of AnycodeX!" << endl;
	return 0;
}
 注意上面的很多细节
 10*10地板的房间 避开(5,5)地板,从(1,1)走到(10,10)有多少种最快的走法;
 仅仅可以上下左右走一格;
 答案:
 【10!-5!*6!】
 以前想过,现在再回忆。


【CVTE20160807】和一个全排列相关的例子

标签:【cvte】

原文地址:http://wzsts.blog.51cto.com/10251779/1835478

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!