Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15490625
  • 博文数量: 112
  • 博客积分: 11195
  • 博客等级: 上将
  • 技术积分: 1989
  • 用 户 组: 普通用户
  • 注册时间: 2005-06-20 11:04
文章分类

全部博文(112)

文章存档

2013年(2)

2012年(27)

2011年(6)

2010年(11)

2009年(6)

2007年(7)

2006年(23)

2005年(30)

分类: C/C++

2006-07-26 00:28:37

istringstream重新赋值以前需要清空以下

#include
#include  

using namespace std;

int main()
{
string source("i world~");
string source2="god->pighead~";
istringstream tmp;
tmp.str(source);
string str,str2;
while(tmp>>str)
cout<tmp.clear();//去掉他看看
tmp.str(source2);
tmp>>str2;
cout<

return 0;
}

汉诺塔,帮人调试的。

#include
using namespace std;
void move (char getone,char putone)
{
 cout<"<}
void hanoi (int n,char one,char two,char three)
{
 if(n==1) move (one,three);
 
 else
 { hanoi(n-1,one,three,two);
  move(one,three);
  hanoi(n-1,two,one,three);
 }
}

int main()
{
 int m;
 cout<<"这是一个汉诺塔的小游戏,程序将教你如何移动你的盘子,A代表第一根指针,B代表第二根指针,C代表第三根指针!"<  cout<<"请输入盘子的个数,按回车键结束!"<cin>>m;
cout<<"移动"<hanoi (m,'A','B','C');
cout<<"谢谢你的使用,请按任意键退出程序!"<return 0;
}

将i am a students!变成students! a am i

#include

struct my_list
{
char * tmp;
int number;
};


int swap(char *a,char* b)
{
int tmp_num,index,str_len,i,b_index;
struct my_list char_list[20];//根据词数修改它的大小
char_list[0].tmp=a;
char_list[0].number=0;
index=0;
str_len=0;
char_list[0].tmp=a;

for(tmp_num=0;*(a+tmp_num)!='\0';tmp_num++)
 {
  char_list[index].number=str_len;
  str_len++;
 
  if(*(a+tmp_num)==' ')
  {
  index++;
  char_list[index].tmp=a+tmp_num+1;
  str_len=0;
  }
 
 }//end for

char_list[index].number=str_len;
b_index=0;
for(;index>=0;index--)
 {
  for(i=0;i   {
      *(b+b_index)=*(char_list[index].tmp+i);
       b_index++;
   }//end for
   
  if(index!=0)
   {
    *(b+b_index)=' ';
    b_index++;
   } 
 
 }//end for
 *(b+b_index)='\0';
 
}//end function

int main()
{
char str2[1024];
char str[]="i am a students!";
swap(str,str2);
printf("%s\n",str2);
}

推理题:有人邀请A,B,C,D,E,F6个人参加一项会议,这6个人有些奇怪,因为他们有很多要求,已知:
1.A,B两人至少有1人参加会议。
2.A,E,F3人中有2人参加会议。
3.B和C两人一致决定,要么两人都去,要么两人都不去。
4.A,D两人中只1人参加会议。
5.C,D两人中也只要1人参加会议。
6.如果D不去,那么E也决定不去。那么最后究竟有哪几个人参加了会议呢?

#include
struct p_num
{
unsigned int a:1;
unsigned int b:1;
unsigned int c:1;
unsigned int d:1;
unsigned int e:1;
unsigned int f:1;
unsigned int g:1;
unsigned int h:1;
};
int main()
{
unsigned char i;
int j;
struct p_num O;

for(i=1;i<64;i++)
 {
 memcpy(&O,&i,1);
 
 if(  ((O.a+O.b)>=1)
   && ((O.a+O.e+O.f)==2 )
   && (((O.b+O.c)==0)||((O.b+O.c)==2) )
   && ((O.a+O.d)==1) && ((O.c+O.d)==1  )
   && ((O.d==0)?((O.d+O.e)==0):((O.d+O.e)>=1) )
  )
   {
    printf("A:%d\tB:%d\tC:%d\tD:%d\tE:%d\tF:%d\n"\
    ,O.a,O.b,O.c,O.d,O.e,O.f);
  }
 }

}

阅读(105365) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~