??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美成a人片免费看久久,久久国产成人午夜AV影院,国产成人无码精品久久久免费 http://m.shnenglu.com/luyulaile/category/11056.htmlI canzh-cnTue, 22 Feb 2011 10:06:36 GMTTue, 22 Feb 2011 10:06:36 GMT60Java与C++的区?/title><link>http://m.shnenglu.com/luyulaile/archive/2011/02/14/140003.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sun, 13 Feb 2011 17:32:00 GMT</pubDate><guid>http://m.shnenglu.com/luyulaile/archive/2011/02/14/140003.html</guid><wfw:comment>http://m.shnenglu.com/luyulaile/comments/140003.html</wfw:comment><comments>http://m.shnenglu.com/luyulaile/archive/2011/02/14/140003.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/luyulaile/comments/commentRss/140003.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/luyulaile/services/trackbacks/140003.html</trackback:ping><description><![CDATA[<p>(1)指针和引用的问题<br>java中没有指针,但是数组名,对象名都是其引用Q?br>指针q有帔R指针Q比如数l名<br>(2)new的区?br>java中的newq回对象的应?br>c++中的newq回其指针,<br>如果c++?br>SparseMatrix s=SparseMatrix(4,4,6,arrays);<br>如果java?br>SparseMatrix s=new SparseMatrix(4,4,6,arrays);<br><br></p> <img src ="http://m.shnenglu.com/luyulaile/aggbug/140003.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/luyulaile/" target="_blank">luis</a> 2011-02-14 01:32 <a href="http://m.shnenglu.com/luyulaile/archive/2011/02/14/140003.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>内存划分Q堆栈区?/title><link>http://m.shnenglu.com/luyulaile/archive/2011/02/14/140002.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sun, 13 Feb 2011 17:14:00 GMT</pubDate><guid>http://m.shnenglu.com/luyulaile/archive/2011/02/14/140002.html</guid><wfw:comment>http://m.shnenglu.com/luyulaile/comments/140002.html</wfw:comment><comments>http://m.shnenglu.com/luyulaile/archive/2011/02/14/140002.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/luyulaile/comments/commentRss/140002.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/luyulaile/services/trackbacks/140002.html</trackback:ping><description><![CDATA[<p>原文地址<a >http://www.ksarea.com/articles/20070829_memory-partition-stack-heap-difference.html</a><br><br>一直对内存区域的划分,E序变量的内存分配问题模p不清。进行多方参考ȝ如下?/p> <p>一、一个经q编译的C/C++的程序占用的内存分成以下几个部分Q?br>1、栈区(stackQ:q译器自动分配和释?nbsp;Q存攑և数的参数倹{局部变量的值等Q甚臛_数的调用q程都是用栈来完成。其操作方式cM于数据结构中的栈?br>2、堆区(heapQ?nbsp;Q一般由E序员手动申请以及释放, 若程序员不释放,E序l束时可能由OS回收 。注意它与数据结构中的堆是两回事Q分配方式类g链表?br>3、全局区(静态区Q(staticQ:全局变量和静态变量的存储是放在一块的Q初始化的全局变量和静态变量在一块区域, 未初始化的全局变量和未初始化的静态变量在盔R的另一块区域。程序结束后ql释攄间?nbsp;<br>4、文字常量区Q常量字W串是攑֜q里的?nbsp;E序l束后由pȝ释放I间?br>5、程序代码区Q存攑ևC的二q制代码?/p> <p>下面的例子可以完全展CZ同的变量所占的内存区域Q?br><coolcode lang=cpp linenum="off"><br>//main.cpp<br>int a = 0; 全局初始化区<br>char *p1; 全局未初始化?br>main()<br>{<br>int b; //栈中<br>char s[] = “abc”; //栈中<br>char *p2; //栈中<br>char *p3 = “123456″; //123456\0在常量区Qp3在栈?br>static int c =0Q?//全局Q静态)初始化区<br>//以下分配得到?0?0字节的区域就在堆?br>p1 = (char *)malloc(10);<br>p2 = (char *)malloc(20);<br>strcpy(p1, “123456″); //123456\0攑֜帔R区,~译器可能会它与p3所指向?#8221;123456″优化成一个地斏V?br>} </coolcode><br><span id=more-124></span><br>二、栈QstackQ和堆(heapQ具体的区别?br>1、在甌方式?br>栈(stackQ? 现在很多人都UC为堆栈,q个时候实际上q是指的栈。它q译器自动理Q无需我们手工控制?例如Q声明函C的一个局部变?int b pȝ自动在栈中ؓb开辟空_在调用一个函数时Q系l自动的l函数的形参变量在栈中开辟空间?br>堆(heapQ? 甌和释攄E序员控Ӟq指明大。容易生memory leak?br>在C中用malloc函数?br>如:p1 = (char *)malloc(10);<br>在C++中用newq算W?br>如:p2 = (char *)malloc(10);<br>但是注意p1本n在全局区,而p2本n是在栈中的,只是它们指向的空间是在堆中?/p> <p>2、申请后pȝ的响应上<br>栈(stackQ?只要栈的剩余I间大于所甌I间Q系l将为程序提供内存,否则报异常提示栈溢出?br>堆(heapQ? 首先应该知道操作pȝ有一个记录空闲内存地址的链表,当系l收到程序的甌Ӟ 会遍历该链表Q寻扄一个空间大于所甌I间的堆l点Q然后将该结点从I闲l点链表中删除,q将该结点的I间分配l程序。另外,对于大多数系l,会在q块内存I间中的首地址处记录本ơ分配的大小Q这P代码中的delete或free语句才能正确的释放本内存I间。另外,׃扑ֈ的堆l点的大不一定正好等于申L大小Q系l会自动的将多余的那部分重新攑օI闲链表中?/p> <p>3、申请大的限制<br>栈(stackQ?在Windows?栈是向低地址扩展的数据结构,是一块连l的内存的区域。这句话的意思是栈顶的地址和栈的最大容量是pȝ预先规定好的Q在WINDOWS下,栈的大小?MQ也有的说是1MQM是一个编译时q定的常数Q,如果甌的空间超q栈的剩余空间时Q将提示overflow。因此,能从栈获得的I间较小?例如Q在VC6下面Q默认的栈空间大是1MQ好像是Q记不清楚了Q。当Ӟ我们可以修改Q打开工程Q依ơ操作菜单如下:Project->Setting->LinkQ在Category 中选中OutputQ然后在Reserve中设定堆栈的最大值和commit?br><strong>注意</strong>Qreserve最gؓ4ByteQcommit是保留在虚拟内存的页文g里面Q它讄的较大会使栈开辟较大的|可能增加内存的开销和启动时间?/p> <p>堆(heapQ? 堆是向高地址扩展的数据结构,是不q箋的内存区域(I闲部分用链表串联v来)。正是由于系l是用链表来存储I闲内存Q自然是不连l的Q而链表的遍历方向是由低地址向高地址。一般来讲在32位系l下Q堆内存可以辑ֈ4G的空_从这个角度来看堆内存几乎是没有什么限制的。由此可见,堆获得的I间比较灉|Q也比较大?/p> <p>4、分配空间的效率?br>栈(stackQ?栈是机器pȝ提供的数据结构,计算Z在底层对栈提供支持:分配专门的寄存器存放栈的地址Q压栈出栈都有专门的指o执行Q这决定了栈的效率比较高。但E序员无法对其进行控制?br>堆(heapQ?是C/C++函数库提供的Q由new或malloc分配的内存,一般速度比较慢,而且Ҏ产生内存片。它的机制是很复杂的Q例如ؓ了分配一块内存,库函C按照一定的法Q具体的法可以参考数据结?操作pȝQ在堆内存中搜烦可用的够大的I间Q如果没有够大的I间Q可能是׃内存片太多Q,有可能调用pȝ功能d加程序数据段的内存空_q样有Z分到_大小的内存,然后q行q回。这样可能引发用h和核心态的切换Q内存的甌Q代价变得更加昂c显Ӟ堆的效率比栈要低得多?/p> <p>5、堆和栈中的存储内容<br>栈(stackQ?在函数调用时Q第一个进栈的是主函数中子函数调用后的下一条指令(子函数调用语句的下一条可执行语句Q的地址Q然后是子函数的各个形参。在大多数的C~译器中Q参数是由右往左入栈的Q然后是子函C的局部变量。注意:静态变量是不入栈的?当本ơ函数调用结束后Q局部变量先出栈Q然后是参数Q最后栈指针指向最开始存的地址Q也是dC子函数调用完成的下一条指令,E序p点l运行?br>堆(heapQ?一般是在堆的头部用一个字节存攑֠的大,堆中的具体内ҎE序员安排?/p> <p>6、存取效率的比较<br>q个应该是显而易见的。拿栈上的数l和堆上的数l来_<br><coolcode lang=cpp linenum="off"><br>void main()<br>{<br>int arr[5]={1,2,3,4,5};<br>int *arr1;<br>arr1=new int[5];<br>for (int j=0;j<=4;j++)<br>{<br>arr1[j]=j+6;<br>}<br>int a=arr[1];<br>int b=arr1[1];<br>}<br></coolcode><br>上面代码中,arr1Q局部变量)是在栈中Q但是指向的I间在堆上Q两者的存取效率Q当然是arr高。因为arr[1]可以直接讉KQ但是访问arr1[1]Q首先要讉K数组的v始地址arr1Q然后才能访问到arr1[1]?/p> <p>总而言之,a而MQ?br>堆和栈的区别可以用如下的比喻来看出:<br>使用栈就象我们去饭馆里吃饭,只管点菜Q声明变量)、付钱、和吃(使用Q,吃饱了就赎ͼ不必理会切菜、洗菜等准备工作和洗、刷锅等扫尾工作Q他的好处是快捷Q但是自由度?br>使用堆就象是自己动手做喜Ƣ吃的菜_比较ȝQ但是比较符合自q口味Q而且自由度大</p> <img src ="http://m.shnenglu.com/luyulaile/aggbug/140002.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/luyulaile/" target="_blank">luis</a> 2011-02-14 01:14 <a href="http://m.shnenglu.com/luyulaile/archive/2011/02/14/140002.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++对象数组作ؓcL员的问题http://m.shnenglu.com/luyulaile/archive/2011/02/14/140001.htmlluisluisSun, 13 Feb 2011 17:08:00 GMThttp://m.shnenglu.com/luyulaile/archive/2011/02/14/140001.htmlhttp://m.shnenglu.com/luyulaile/comments/140001.htmlhttp://m.shnenglu.com/luyulaile/archive/2011/02/14/140001.html#Feedback0http://m.shnenglu.com/luyulaile/comments/commentRss/140001.htmlhttp://m.shnenglu.com/luyulaile/services/trackbacks/140001.htmlclass ObjectB{};

class ObjectA{
public:
    ObjectB array[5];//对象数组作ؓcȝ成员
}

那样的话对象数组的初始化会变得很ȝQ?br>因ؓ数组名不能作为左|所以不可以指针传递的方式赋倹{?br>而且不能通过参数列表Q构造函数后面加一个冒P的方式初始化Q?br>所以只能让cObjectA自动调用cObjectB的无参构造函?
---------------
#include <iostream.h>
#include 
"stdlib.h"
class   ObjectB{
public:
    
int a;
public:
    ObjectB(
int m=0)
    
{
        a
=m;
    }

}
;
class   ObjectA
public:
        ObjectB   Array[
5]; 
public
        ObjectA(
int   *p)
        
{
            Array[
0]=ObjectB(p[0]);
            Array[
1]=ObjectB(p[1]);
            Array[
2]=ObjectB(p[2]);
        }
 
}
;

int main()
{
    
int p[5]={0,2,2,3,4};
    ObjectA am
=ObjectA(p);
    cout
<<am.Array[1].a<<endl;
    
return 0;
}

---------------

我们可以使用替代方式Q?br>class A{};

classB{
public:
    A*a;//Acd的指针作为类的成?br>}
同样带来很大的问题,
Q?Q浅拯Q深拯的问题,除非重蝲拯构造函敎ͼcB才能实现深拷贝,因ؓ成员中有指针Q所以无法简单的用拷贝构造函数生成一个新对象Q而用无参构造函数生成的新对象也会有问题Q因为里面的指针一般都默认为NULL了?br>
重蝲拯构造函数的时候需要申请一定长度的内存Q将拯对象的指针所指向的空间拷贝到新申LI间Q再q行操作。注意申请后要释放?br>一个拷贝构造函数的例子
SparseMatrix::SparseMatrix(const SparseMatrix&s)
    
{
      Rows
=s.Rows;
   Cols
=s.Cols;
   Count
=s.Count;
   smArray
=new Trituple[6];
//此处q需要复制对?/span>
    }


----------------------
补充知识Q?br>------------------http://www.ksarea.com/articles/20070829_memory-partition-stack-heap-difference.html

C/C++应该是大学里最先接触的~程语言Q它们的重要性不a而喻。但是我始终q“数组名就是指?#8221;的错误信条到现在Q可能是因ؓ大学老师错误的讲解我一直保留着q种误解。指针是C/C++语言的特Ԍ而数l名与指针有太多的相|甚至很多时候,数组名可以作为指针用,所以也隑օ在学习中两者؜淆。这里介l下指针和数l名的区?

1.指针和数l名占据的内存空间大不一P如下E序1Q?br>
char str[10];
char *pstr=str;
cout<<
cout<<sizeof

W一行输出结果是Q?0Q第二行输出l果是:4

从这里我们可以看出:数组名对应着Q而不是指向)一块内存(数组所占的内存区域Q或者说是指代数l这U数据结构,其地址与容量在生命期内保持不变Q只有数l的内容可以改变。指针对应着一个占?个字节(Win32Q的内存区域Q而指向这4个字节所存储的地址所对应的内存单元,它可以指向Q意类型的内存块。因此,sizeof(str)gؓ数组占据的内存空间大即10个字节,而sizeof(pstr)gؓ指针的值占据的内存I间大小?个字节?/strong>

2.数组名不是指针,但是在一定的情况下{换ؓ指代数组的首地址的指针,而这个数l名转ؓ的指针只能是指针帔R?br>在以下两U情况下才能q行q种转换Q?br>a.在程?W二行代码中Q将数组名直接赋值给指针Q此时数l名转换为指向数l的首单元的帔R指针?br>b.直接数l名作ؓ指针形参的时候,数组名则转换为指向数l的首单元的帔R指针q行传递,如下E序2Q?br>
void fun(char str[])
{
cout<<
str++;
}
void main()
{

char str1[5];
fun(str1);

}

注意Q数l名作ؓ函数形参q行传递时Q在子函C内,它已l不再是一个指针常量,而是变成一个真正的指针Q可以进行增减等操作Q可以被修改。所以程?中子E序W一条语句输出的sizeof(str)的gؓ4.

既然数组名可以被看作指针帔RQ而常量是不能修改的,那么如下代码是不允许的:

char str[10];
str++;

但如下代码则合法的:

char str[10];
char *pstr=str;
pstr++;

3.使用指针讉K数组和用数l名讉K数组本质不同?br>例如Q?br>
char str[7]=”ksarea”;
char *pstr=str;
cout<<<


其中str[3]和pstr[3]q回的都是字W?#8217;r'Q但是编译器产生的执行代码却不一栗对于str[3]Q执行代码是从str开始,向后Ud两个字节Q然后取出其中的字符Q而对于pstr[3]Q执行代码是从pstr中取出地址Q然后在其上?Q然后取出对应内存中的字W?/strong>当然Q如果pstr是指向int型的指针Q那么pstr[3]的处理过E是从pstr中取出地址Q然后在其上加上3*sizeof(int)Q最后取出对应内存中的字W,其他的数据类型一ơ类推?

luis 2011-02-14 01:08 发表评论
]]>
Java 命名规范zthttp://m.shnenglu.com/luyulaile/archive/2010/12/21/137128.htmlluisluisTue, 21 Dec 2010 08:44:00 GMThttp://m.shnenglu.com/luyulaile/archive/2010/12/21/137128.htmlhttp://m.shnenglu.com/luyulaile/comments/137128.htmlhttp://m.shnenglu.com/luyulaile/archive/2010/12/21/137128.html#Feedback0http://m.shnenglu.com/luyulaile/comments/commentRss/137128.htmlhttp://m.shnenglu.com/luyulaile/services/trackbacks/137128.html完全版java规范Q?a >http://www.huihoo.org/code/java_code_conventions.html#71

 



luis 2010-12-21 16:44 发表评论
]]>
switch表达?/title><link>http://m.shnenglu.com/luyulaile/archive/2010/12/19/136959.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sun, 19 Dec 2010 13:41:00 GMT</pubDate><guid>http://m.shnenglu.com/luyulaile/archive/2010/12/19/136959.html</guid><wfw:comment>http://m.shnenglu.com/luyulaile/comments/136959.html</wfw:comment><comments>http://m.shnenglu.com/luyulaile/archive/2010/12/19/136959.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/luyulaile/comments/commentRss/136959.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/luyulaile/services/trackbacks/136959.html</trackback:ping><description><![CDATA[<span style="COLOR: red"><font size=2>switch(表达?<br>{ <br>      case 帔R表达?:<br>         语句1;<br>      break;<br>      <br>      case 帔R表达?:<br>         语句2;<br>      break; </font> <p><font size=2></font></p> <p><font size=2>……<br>      case 帔R表达式n:<br>         语句n;<br>      break; </font></p> <p><font size=2>      default:<br>         语句n+1;<br>      break;<br>}</font></p> </span> <img src ="http://m.shnenglu.com/luyulaile/aggbug/136959.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/luyulaile/" target="_blank">luis</a> 2010-12-19 21:41 <a href="http://m.shnenglu.com/luyulaile/archive/2010/12/19/136959.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>argmaxhttp://m.shnenglu.com/luyulaile/archive/2010/12/19/136937.htmlluisluisSun, 19 Dec 2010 06:58:00 GMThttp://m.shnenglu.com/luyulaile/archive/2010/12/19/136937.htmlhttp://m.shnenglu.com/luyulaile/comments/136937.htmlhttp://m.shnenglu.com/luyulaile/archive/2010/12/19/136937.html#Feedback0http://m.shnenglu.com/luyulaile/comments/commentRss/136937.htmlhttp://m.shnenglu.com/luyulaile/services/trackbacks/136937.html 



luis 2010-12-19 14:58 发表评论
]]>
JAVA获取随机?/title><link>http://m.shnenglu.com/luyulaile/archive/2010/12/19/136893.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sat, 18 Dec 2010 16:56:00 GMT</pubDate><guid>http://m.shnenglu.com/luyulaile/archive/2010/12/19/136893.html</guid><wfw:comment>http://m.shnenglu.com/luyulaile/comments/136893.html</wfw:comment><comments>http://m.shnenglu.com/luyulaile/archive/2010/12/19/136893.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/luyulaile/comments/commentRss/136893.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/luyulaile/services/trackbacks/136893.html</trackback:ping><description><![CDATA[<p>本文来自CSDN博客<a >http://blog.csdn.net/pointbin/archive/2006/01/12/576957.aspx</a></p> <p> <br>在java.lang.Math中有个Math.random()ҎQ它可以产生0-1之间Q包?但不包括1Q的L数<br><br><br>在Java中我们可以用java.util.RandomcL产生一个随机数发生器。它有两UŞ式的构造函敎ͼ分别是Random()和Random(long seed)。Random()使用当前旉即System.currentTimeMillis()作ؓ发生器的U子QRandom(long seed)使用指定的seed作ؓ发生器的U子?/p> <p>        随机数发生器(Random)对象产生以后Q通过调用不同的methodQnextInt()、nextLong()、nextFloat()、nextDouble(){获得不同类型随机数?/p> <p>       1>生成随机?br>           Random random = new Random();<br>           Random random = new Random(100);//指定U子?00<br>           random调用不同的方法,获得随机数?br>           如果2个Random对象使用相同的种子(比如都是100Q,q且以相同的序调用相同的函敎ͼ那它们返回值完全相同。如下面代码中两个Random对象的输出完全相?br>          import java.util.*;<br>          class TestRandom {<br>                public static void main(String[] args) {<br>                     Random random1 = new Random(100);<br>                     System.out.println(random1.nextInt());<br>                     System.out.println(random1.nextFloat());<br>                     System.out.println(random1.nextBoolean());<br>                     Random random2 = new Random(100);<br>                     System.out.println(random2.nextInt());<br>                     System.out.println(random2.nextFloat());<br>                     System.out.println(random2.nextBoolean());<br>                }<br>            }</p> <p>        2>指定范围内的随机?br>             随机数控制在某个范围?使用模数q算W?<br>            import java.util.*;<br>                 class TestRandom {<br>                      public static void main(String[] args) {<br>                           Random random = new Random();<br>                           for(int i = 0; i < 10;i++) {<br>                               System.out.println(Math.abs(random.nextInt())%10);<br>                           }<br>                      }<br>                 }<br>             获得的随机数有正有负的,用Math.abs使获取数据范围ؓ非负?/p> <p>       3>获取指定范围内的不重复随机数<br>            import java.util.*;<br>            class TestRandom {<br>                  public static void main(String[] args) {<br>                       int[] intRet = new int[6]; <br>                       int intRd = 0; //存放随机?br>                       int count = 0; //记录生成的随机数个数<br>                       int flag = 0; //是否已经生成q标?br>                       while(count<6){<br>                            Random rdm = new Random(System.currentTimeMillis());<br>                            intRd = Math.abs(rdm.nextInt())%32+1;<br>                            for(int i=0;i<count;i++){<br>                                if(intRet[i]==intRd){<br>                                    flag = 1;<br>                                    break;<br>                                }else{<br>                                    flag = 0;<br>                                }<br>                            }<br>                            if(flag==0){<br>                                intRet[count] = intRd;<br>                                count++;<br>                            }<br>                   }<br>                  for(int t=0;t<6;t++){<br>                      System.out.println(t+"->"+intRet[t]);<br>                  }<br>               }<br>            }</p> <p> </p> <img src ="http://m.shnenglu.com/luyulaile/aggbug/136893.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/luyulaile/" target="_blank">luis</a> 2010-12-19 00:56 <a href="http://m.shnenglu.com/luyulaile/archive/2010/12/19/136893.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>joj 1097 System overload U瑟芬问?单题http://m.shnenglu.com/luyulaile/archive/2009/07/23/90881.htmlluisluisWed, 22 Jul 2009 23:23:00 GMThttp://m.shnenglu.com/luyulaile/archive/2009/07/23/90881.htmlhttp://m.shnenglu.com/luyulaile/comments/90881.htmlhttp://m.shnenglu.com/luyulaile/archive/2009/07/23/90881.html#Feedback0http://m.shnenglu.com/luyulaile/comments/commentRss/90881.htmlhttp://m.shnenglu.com/luyulaile/services/trackbacks/90881.html题意好理解,旉上提高不了,试数据很少可以交表

?展开


luis 2009-07-23 07:23 发表评论
]]>
c/c++输入输出全归U?/title><link>http://m.shnenglu.com/luyulaile/archive/2009/07/21/90735.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Tue, 21 Jul 2009 07:18:00 GMT</pubDate><guid>http://m.shnenglu.com/luyulaile/archive/2009/07/21/90735.html</guid><wfw:comment>http://m.shnenglu.com/luyulaile/comments/90735.html</wfw:comment><comments>http://m.shnenglu.com/luyulaile/archive/2009/07/21/90735.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/luyulaile/comments/commentRss/90735.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/luyulaile/services/trackbacks/90735.html</trackback:ping><description><![CDATA[<p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">今天看完一牛人博文,受益匪浅Q小C下。原文更详细<a >http://blog.csdn.net/lewsn2008/archive/2008/04/16/2295790.aspx</a><br>首先我们呢看一下输入操作的原理Q?E序的输入都建有一个缓冲区Q即输入~冲区。一ơ输入过E是q样的,当一ơ键盘输入结束时会将输入的数据存入输入缓冲区Q而cin{输入输出函数直接从输入~冲Z取数据。正因ؓcin{输入输出函数是直接从缓冲区取数据的Q所以有时候当~冲Z有残留数据时Qcin函数会直接取得这些残留数据而不会请求键盘输入?br>---------------</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">1Q要注意不同的函数是否接受空格符、是否舍弃最后的回RW的问题!</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">d字符Ӟ</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">scanf()以SpaceI格、Enter、Tabl束一ơ输入,不会舍弃最后的回RW(卛_车符会残留在~冲ZQ,Q区别读字符串时会清楚)//所以可以用getchar()清除Q?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">getchar()以Enterl束输入Q也不会舍弃最后的回RW;</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">d字符串时Q?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">scanf()以Space、Enter、Tabl束一ơ输入,会舍弃最后的回RW(区别dW时Q和所有的I格{等?o:p></o:p></p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">gets()以Enterl束输入Q空gl束Q,接受I格Q会舍弃最后的回RW!</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana"><o:p> </o:p></p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">W二Qؓ了避免出Cq问题,必须要清I缓冲区的残留数据,可以用以下的Ҏ解决Q?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">Ҏ1QC语言里提供了函数清空~冲区,只要在读数据之前先清I缓冲区没问题了!<o:p></o:p></p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">       q个函数是fflush(stdin)?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">Ҏ2Q自己取出缓冲区里的D留数据?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">       scanf("%[^\n]",string);</p> -------------------------<br>cin的学?br> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">一. cin<<</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">该操作符是根据后面变量的cdd数据?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">输入l束条g   Q遇到Enter、Space、Tab键?q个很重要!)</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">对结束符的处?Q清楚缓冲区中得输入结束的l束W?Enter、Space、Tab)</p> (q里有一炚w题,<br>int i;<br>char c[100];<br>cin>>i;<br>cin.getline(str,100);<br>cout<<str;<br>如果输入是:12     adjf回R<br>输出先是空格然后adjfQ?br>如果输入是:12回Radjf回R<br>输出是adjf.<br>看来cin>>要在q用Ӟ比如cin>>a>>b;或者cin>>a;cin>>b消除I格能力才体现?br>)<br> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">二.cin.get()</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">该函数有三种格式Q无参,一参数Q二参数</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">即cin.get(),  cin.get(char ch),  cin.get(array_name, Arsize)</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana"> </p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">        QiQ读取字W的情况Q?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">输入l束条gQEnter键(遇空gl束Q?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">对结束符处理Q不丢弃~冲Z的Enter</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">cin.get() ?cin.get(char ch)用于d字符Q他们的使用是相似的Q?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">卻Ich=cin.get() ?cin.get(ch)是等L?br></p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">试E序Q?br>#include <iostream></p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">using namespace std;</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">int main()</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">{</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">       char c1, c2;</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">       cin.get(c1);</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">       cin.get(c2);</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">       cout<<c1<<" "<<c2<<endl;   // 打印两个字符</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">       cout<<(int)c1<<" "<<(int)c2<<endl; // 打印q两个字W的ASCII?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">       return 0; </p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">}</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">试一输入Q?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">a[Enter]</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">输出:</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">a</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana"> </p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">97 10</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">【分析】会发现只执行了一ơ从键盘输入Q显然第一个字W变量取?a', W二个变量取的是Enter(ASCIIgؓ10)Q这是因函数不丢弃上ơ输入结束时的Enter字符Q所以第一ơ输入结束时~冲ZD留的是上次输入l束时的Enter字符Q?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana"> </p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">试二输入:</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">a b[Enter]</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">输出Q?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">a </p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">97 32</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">【分析】显然第一个字W变量取?a', W二个变量取的是Space(ASCIIgؓ32)。原因同上,没有丢弃Space字符?/p> <p style="FONT-SIZE: 18pt; FONT-FAMILY: Verdana">            QiiQ读取字W串的情况:</p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">cin.get(array_name, Arsize)是用来读取字W串的,可以接受I格字符Q遇到Enterl束输入Q按照长?Arsize)d字符, 会丢弃最后的Enter字符?/p> <span style="FONT-SIZE: 14pt">                      <span style="FONT-SIZE: 18pt">Qi i iQcin.getline()</span></span> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">cin.getline() ?cin.get(array_name, Arsize)的读取方式差不多Q以Enterl束Q可以接受空格字W。按照长?Arsize)d字符, 会丢弃最后的Enter字符?/p> <p style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">但是q两个函数是有区别的Q?/p> cin.get(array_name, Arsize)<br><span style="COLOR: #ff0000">当输入的字符串超长时Q不会引起cin函数的错误,后面的cin操作会l执行,只是直接从缓冲区中取数据。但是cin.getline()<br><br>当输入超长时Q会引vcin函数的错误,后面的cin操作不再执行。(具体原因在下一部分"cin的错误处?中详l介l)<br></span><br>------------<br>cin的错误处?br><br> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">E序执行时有一个标志变量来标志输入的异常状态,其中有三位标志位分别用来标志三种异常信息Q他们分别是Q?/span><span lang=EN-US>failbit</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q?/span><span lang=EN-US>eofbit</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q?/span><span lang=EN-US>badbit</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。这三个标志位在标志变量中是q样分配的:</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>____________________________________</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>|<span style="mso-spacerun: yes">     </span>2<span style="mso-spacerun: yes">     </span>|<span style="mso-spacerun: yes">     </span>1<span style="mso-spacerun: yes">    </span>|<span style="mso-spacerun: yes">     </span>0<span style="mso-spacerun: yes">     </span>|</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>|<span style="mso-spacerun: yes">  </span>failbit<span style="mso-spacerun: yes">  </span>|<span style="mso-spacerun: yes">  </span>eofbit<span style="mso-spacerun: yes">  </span>|<span style="mso-spacerun: yes">   </span>badbit<span style="mso-spacerun: yes">  </span>|</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>|___________|__________|___________|</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">看一下这几个标志位的作用</span><span lang=EN-US>(</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">引用</span><span lang=EN-US>msdn)</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>badbit, to record a loss of integrity of the stream buffer.</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>eofbit, to record end-of-file while extracting from a stream.</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>failbit, to record a failure to extract a valid field from a stream.</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>In addition, a useful value is goodbit, where no bits are set.</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><o:p> </o:p></span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接下来我么看几个</span><span lang=EN-US>ios</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">cȝ数据定义</span><span lang=EN-US>(</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">引用</span><span lang=EN-US>msdn)</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>typedef T2 iostate; </span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>static const iostate badbit, eofbit, failbit, goodbit;</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><o:p> </o:p></span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">q里</span><span lang=EN-US>ios</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">cd义了q四个常?/span><span lang=EN-US>badbit, eofbit, failbit, goodbit</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q其实这四个标志帔R是取对应标志位的掩码,也即输入的四U异常情况!</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以上四个帔R对应的取gؓQ?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>ios::badbit<span style="mso-spacerun: yes">    </span>001<span style="mso-spacerun: yes">   </span></span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">输入Q输出)出现致命错误,不可挽回</span><span lang=EN-US><span style="mso-spacerun: yes">  </span></span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>ios::eofbit<span style="mso-spacerun: yes">    </span>010<span style="mso-spacerun: yes">   </span></span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">已经到达文g?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>ios::failbit<span style="mso-spacerun: yes">   </span>100<span style="mso-spacerun: yes">   </span></span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">输入Q输出)出现非致命错误Q可挽回</span><span lang=EN-US> </span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>ios::goodbit<span style="mso-spacerun: yes">   </span>000<span style="mso-spacerun: yes">   </span></span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">状态完全正?/span><span lang=EN-US>, </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">各异常标志位都ؓ</span><span lang=EN-US>0</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt">如果出现输入错误Q则cin不再工作Q我们可以用cin.clear()重置标记位?span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><br>试E序</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>#include <iostream></span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>using namespace std;</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>int main ()</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>{</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><span style="mso-spacerun: yes"> </span>char ch, str[20];</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><span style="mso-spacerun: yes"> </span>cin.getline(str, 5);</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><span style="mso-spacerun: yes"> </span>cout<<"flag1:"<<cin.good()<<endl;<span style="mso-spacerun: yes">    </span>// </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">查看</span><span lang=EN-US>goodbit</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">状态,x否有异常</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><span style="mso-spacerun: yes"> </span>cin.clear();<span style="mso-spacerun: yes">                         </span>// </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">清除错误标志</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><span style="mso-spacerun: yes"> </span>cout<<"flag1:"<<cin.good()<<endl;<span style="mso-spacerun: yes">    </span>// </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">清除标志后再查看异常状?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><span style="mso-spacerun: yes"> </span>cin>>ch; </span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><span style="mso-spacerun: yes"> </span>cout<<"str:"<<str<<endl;</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><span style="mso-spacerun: yes"> </span>cout<<"ch :"<<ch<<endl;</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US><span style="mso-spacerun: yes"> </span>return 0;</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>}</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">试输入Q?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>12345[Enter]</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">输出Q?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>flag1:0<span style="mso-spacerun: yes">  </span>// good()</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">q回</span><span lang=EN-US>false</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">说明有异?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>flag2:1<span style="mso-spacerun: yes">  </span>// good()</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">q回</span><span lang=EN-US>true</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">说明Q?/span><span lang=EN-US>clear()</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">已经清除了错误标?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>str:1234</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US>ch :5</span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><br>但是当前一ơ读取数据出错后Q如果缓冲区没有清空的话Q重|错误标志还不够Q要是能缓冲区的残留数据清IZ好了哦Q下面我们再来看一个很重要的函敎ͼcin.ignore()<br></span></p> <span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">q个函数用来丢弃输入~冲Z的字W,W一参数定义一个数Q第二个参数定义一个字W变量?/span><br>例:</span><span lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">cin.ignore(5, 'a'); </span><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">函数不断从~冲Z取一个字W丢弃,直到丢弃的字W数辑ֈ</span><span lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">5</span><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">或者读取的字符?/span><span lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">'a'</span><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">?/span><br> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其实该函数最常用的方式是q样的,第一个参数设的非常大Q将W二个参数设?/span><span lang=EN-US>'\n'</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q这样就可以~冲Z回RW中的所有残留数据,因ؓ一般情况下前面输入D留的数据是没有用的Q所以在q行Cơ输入操作前缓冲区中所有数据清I是比较合理?/span></p> <p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如:</span><span lang=EN-US>cin.ignore(1024, '\n'); </span></p> <br>------ <img src ="http://m.shnenglu.com/luyulaile/aggbug/90735.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-07-21 15:18 <a href="http://m.shnenglu.com/luyulaile/archive/2009/07/21/90735.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>joj 1946 compound wordshttp://m.shnenglu.com/luyulaile/archive/2009/07/19/90489.htmlluisluisSun, 19 Jul 2009 02:09:00 GMThttp://m.shnenglu.com/luyulaile/archive/2009/07/19/90489.htmlhttp://m.shnenglu.com/luyulaile/comments/90489.htmlhttp://m.shnenglu.com/luyulaile/archive/2009/07/19/90489.html#Feedback0http://m.shnenglu.com/luyulaile/comments/commentRss/90489.htmlhttp://m.shnenglu.com/luyulaile/services/trackbacks/90489.htmlSample Input
a
alien
born
less
lien
never
nevertheless
new
newborn
the
zebra

Sample Output

alien
newborn
输入是字典序的,题意是讲一个单词分成两半,且两半都出现在输入中Q则此单词输出。下面的代码是对每一个单词尝试所有的分拆ҎQ一个个d找是否拆成的?/pre>
个是否都存在Q如果两个字串都存在Q则输出Q同时蟩出@环(否则可能重复输出Q?/pre>
其实有更高效的方法,是到每个单词前面寻找是否有他的字串Q比如newborn 前面有new,neverthelsess 前面有neverQ,有的话,再找后半部分是否在输入中?/pre>
----
获取子串的方法?string   B   =   A.substr(start,length);   
  start为子串在A中的开始位|?  
  length为子串的长度
例子   
  void   main()  
  {  
          string   st="ifn",b;  
  b=st.substr(0,2);  
  cout<<b;  
  }  
  l果   if
----
Ҏ代码


luis 2009-07-19 10:09 发表评论
]]>获取行输入,一行一个字W串http://m.shnenglu.com/luyulaile/archive/2009/07/18/90435.htmlluisluisSat, 18 Jul 2009 08:11:00 GMThttp://m.shnenglu.com/luyulaile/archive/2009/07/18/90435.htmlhttp://m.shnenglu.com/luyulaile/comments/90435.htmlhttp://m.shnenglu.com/luyulaile/archive/2009/07/18/90435.html#Feedback0http://m.shnenglu.com/luyulaile/comments/commentRss/90435.htmlhttp://m.shnenglu.com/luyulaile/services/trackbacks/90435.html2152: A Special Sorting
Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE
stdin/stdout 3s 8192K 356 152 Standard

Give you a sequence of words, can you sort them in dictionary order?

eg.

yes
accidental
baby
accept
accident
In dictionary order, those words should be printed as the following
accept
accident
accidental
baby
yes
But we will make an interesting rule this time. See your keyboard or the picture below:

there are ONLY 26 letters in lower-case we will use, and we assume that the letter above is bigger than the letter below, and the left is bigger than the right. For example, 'q' is bigger than 'a', 'c' is bigger than 'v'. So the example at the beginning whill be...

Input and Output

the input will only contain a sequence of words which is less than 1500. the output should print the sorted words each in a single line.

Sample Input

yes
accidental
baby
accept
accident

Sample Output

baby
accident
accidental
accept
yes

水题啊!
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int Map[27];
struct M{
 char s[30];
}S[1500];
char table[26]={'q','w','e','r','t','y','u','i','o','p','a','s','d',
'f','g','h','j','k','l','z','x','c','v','b','n','m'};
bool operator<(M a,M b)
{
 int i=strlen(a.s);
 int j=strlen(b.s);
 if(i<j)
 j=i;
 for(int k=0;k<j;k++)
 {
  if(Map[(a.s[k])-'a']<Map[(b.s)[k]-'a'])
  return false;
  if(Map[(a.s[k])-'a']>Map[(b.s)[k]-'a'])
  return true;
 }
 return i==j;//Èç¹ûabcd,abc,abcd<abc
}
void search(char key)
{
 int i;
for(i=0;i<26;i++)
{
 if(key==table[i])
 {
  Map[key-'a']=i;
  break;
 }
}
}
  int main()
  {
  freopen("s.txt","r",stdin);  
  freopen("key.txt","w",stdout);
  int i;
  string t;
  memset(S,0,sizeof(S));
  for(i=0;i<26;i++)
  {
  search('a'+i);
  }
  i=0;
  while(!cin.eof())
   { 
 cin.getline(S[i++].s,30);//不能用cin>>s;否则runtime  error
   }
 sort(S,S+i-1);
 for(int j=0;j<i-1;j++)//必须用i-1,最后还有个I?br> cout<<S[j].s<<endl;
  //system("PAUSE");
  return   0;
  }
奇怪的是在vc上能?br>string s ;
while(cin>>s)
{};
在dev c++ 上不行?
后来才发现可?br>string s ;
while(cin>>s)
{};
但是不能?memset(S,0,sizeof(S));


luis 2009-07-18 16:11 发表评论
]]>
joj 1253 Magic Numbers 不难Q但是可以做?/title><link>http://m.shnenglu.com/luyulaile/archive/2009/07/17/90393.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Fri, 17 Jul 2009 15:21:00 GMT</pubDate><guid>http://m.shnenglu.com/luyulaile/archive/2009/07/17/90393.html</guid><wfw:comment>http://m.shnenglu.com/luyulaile/comments/90393.html</wfw:comment><comments>http://m.shnenglu.com/luyulaile/archive/2009/07/17/90393.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/luyulaile/comments/commentRss/90393.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/luyulaile/services/trackbacks/90393.html</trackback:ping><description><![CDATA[<p>可以用long longQ可以不用高_ֺ法Q大整数乘法Q?br>?开始遍历到9999999999/n;因ؓ最多只?0位。相乘之U也应当于9999999999.</p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">  n</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">9999999999.0</span><span style="COLOR: #000000">;<br>  </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">  m,temp;<br>  </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">m)<br> {<br>    <br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">m;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>         {<br>          </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">判断</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">         }<br>}</span></div> <img src ="http://m.shnenglu.com/luyulaile/aggbug/90393.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-07-17 23:21 <a href="http://m.shnenglu.com/luyulaile/archive/2009/07/17/90393.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>joj 1199 求n!最双一位非零数http://m.shnenglu.com/luyulaile/archive/2009/07/08/89533.htmlluisluisWed, 08 Jul 2009 02:45:00 GMThttp://m.shnenglu.com/luyulaile/archive/2009/07/08/89533.htmlhttp://m.shnenglu.com/luyulaile/comments/89533.htmlhttp://m.shnenglu.com/luyulaile/archive/2009/07/08/89533.html#Feedback0http://m.shnenglu.com/luyulaile/comments/commentRss/89533.htmlhttp://m.shnenglu.com/luyulaile/services/trackbacks/89533.html求模的思想
#include<iostream>
#include<cstdlib>
#include<iomanip>
using namespace std;

  int main()
  {
  //freopen("s.txt","r",stdin);
  //freopen("key.txt","w",stdout);
  int n;
  int temp;
  while(cin>>n)
  {
  cout<<setw(5)<<n<<" -> " ;
  temp=1;
  for(int j=1;j<=n;j++)
  {
   int i=j;
   while(i%10==0)
   {
    i/=10;
   }
   while(i%5==0)
   {
    i/=5;
    temp/=2;
   }
   
   temp*=i;
   
  //¼ÆËãĩλ
   temp%=100000;
  }
  while(temp%10==0)
  temp/=10;
  temp%=10;
  cout<<temp<<endl;
  }

  //system("PAUSE");
  return   0;
  }
一U是分类的思想

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
 long a[10001]={0,1,2,6,4,2},b[5]={0,2,4,8,6},i,m,n;
 for(i=6;i<=10000;i++)
 {
  m=i%5;
  n=i/5;
  if(m!=0)
   a[i]=a[i-1]*i%10;
  else
   a[i]=b[(n-1)%4+1]*a[n]%10;
 }
 while(cin>>n)
  cout<<setw(5)<<n<<" -> "<<a[n]<<endl;
 return 0;
}



luis 2009-07-08 10:45 发表评论
]]>
joj 1125 spell checker字符串处?maphttp://m.shnenglu.com/luyulaile/archive/2009/07/06/89395.htmlluisluisMon, 06 Jul 2009 12:13:00 GMThttp://m.shnenglu.com/luyulaile/archive/2009/07/06/89395.htmlhttp://m.shnenglu.com/luyulaile/comments/89395.htmlhttp://m.shnenglu.com/luyulaile/archive/2009/07/06/89395.html#Feedback0http://m.shnenglu.com/luyulaile/comments/commentRss/89395.htmlhttp://m.shnenglu.com/luyulaile/services/trackbacks/89395.html
Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE
stdin/stdout 3s 8192K 135 46 Standard

You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given words using a known dictionary of all correct words in all their forms.

If the word is absent in the dictionary then it can be replaced by correct words (from the dictionary) that can be obtained by one of the following operations:

  • deleting of one letter from the word;
  • replacing of one letter in the word with an arbitrary letter;
  • inserting of one arbitrary letter into the word.

Your task is to write the program that will find all possible replacements from the dictionary for every given word.

Input

This problem consists of several test cases, each of which is described below:

The first part of each test case contains all words from the dictionary. Each word occupies its own line. This part is finished by the single character '#' on a separate line. All words are different. There will be at most 10000 words in the dictionary.

The next part of the test case contains all words that are to be checked. Each word occupies its own line. This part is also finished by the single character '#' on a separate line. There will be at most 50 words that are to be checked.

All words in the input (words from the dictionary and words to be checked) consist only of small alphabetic characters and each one contains 15 characters at most.

The first line of the input contains an integer N, which is the number of test cases in the input, followed by N test cases described above.

Output

For each test case, first write to the output 'Scenario #k:', where k is the number of test case of input. Then on the next line write to the output exactly one line for every checked word in the order of their appearance in the second part of the test case. If the word is correct (i.e. it exists in the dictionary) write the message: "<checked word> is correct". If the word is not correct then write this word first, then write the character ':' (colon), and after a single space write all its possible replacements, separated by spaces. The replacements should be written in the order of their appearance in the dictionary (in the first part of the input file). If there are no replacements for this word then the line feed should immediately follow the colon.

Print a blank line after each test case.

Sample Input

1
i
is
has
have
be
my
more
contest
me
too
if
award
#
me
aware
m
contest
hav
oo
or
i
fi
mre
#

Sample Output

Scenario #1:
me is correct
aware: award
m: i my me
contest is correct
hav: has have
oo: too
or:
i is correct
fi: i
mre: more me

启发Qmap用于查找字符串还是很爽的?br>
#include<iostream>
#include
<cstdlib>
#include
<map>
#include
<math.h>
#include
<string>
using namespace std;
map 
<string,int> ans;
bool solve(char *s,char *key)
{
    
int i=strlen(s);
    
int j=strlen(key);
    
int num=0;
    
if(abs(i-j)>1)
    
return false;
    
else
    {
        
if(i-j==1)//比字怸多一?nbsp;
        {
            
for(int k=0;k<j&&num<=2;k++)
            {
                
if(s[k+num]!=key[k])
                {
                    num
++;
                    k
--;
                }
            }
            
if(num<=1)
            
return true;
            
else
            
return false;
        }
        
if(j-i==1)//比字怸一?nbsp;
        {
            
for(int k=0;k<i&&num<=2;k++)
            {
                
if(s[k]!=key[k+num])
                {
                    num
++;
                  k
--;
                } 
            }
            
if(num<=1)
            
return true;
            
else
            
return false;
        }
        
if(i==j)
        {
            
for(int k=0;k<i&&num<=2;k++)
            {
                
if(s[k]!=key[k])
                num
++;
            }
            
if(num==1)
            
return true;
            
else
            
return false;
        }
    }
}
  
int main()
  {
  freopen(
"s.txt","r",stdin);
  freopen(
"key.txt","w",stdout);
  
int num,casetime=0;
  
int i,j,k;
  cin
>>num;
  
char s[16];
  
char str[10000][16];
  
while(num--)
  {
        casetime
++;
        cout
<<"Scenario #"<<casetime<<":"<<endl;
        ans.clear();
        i
=0;
        
while(1)
        {
            scanf(
"%s",&str[i]);
            
if(str[i][0]=='#')
              
break;
            ans[str[i]]
=1;
            i
++;
        }
        
while(1)
        {
            scanf(
"%s",&s);
            
if(s[0]=='#')
              
break;
            
if(ans[s]==1
            {
                cout
<<s<<" is correct"<<endl;

            } 
            
else
            {
                cout
<<s<<":";
               
for(int j=0;j<i;j++)
              {
                
if(solve(s,str[j]))
                  cout
<<" "<<str[j];
              }
              cout
<<endl;
            } 
        }
        cout
<<endl;
        
  }

  
//system("PAUSE");
  return   0;
  }


luis 2009-07-06 20:13 发表评论
]]>
joj 1274 Pig Latin 字符串处?/title><link>http://m.shnenglu.com/luyulaile/archive/2009/07/03/89183.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Fri, 03 Jul 2009 10:04:00 GMT</pubDate><guid>http://m.shnenglu.com/luyulaile/archive/2009/07/03/89183.html</guid><wfw:comment>http://m.shnenglu.com/luyulaile/comments/89183.html</wfw:comment><comments>http://m.shnenglu.com/luyulaile/archive/2009/07/03/89183.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/luyulaile/comments/commentRss/89183.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/luyulaile/services/trackbacks/89183.html</trackback:ping><description><![CDATA[<div id="iiiw8ao" class=prob_text> <p>You have decided that PGP encryptation is not strong enough for your email. You have decided to supplement it by first converting your clear text letter into Pig Latin before encrypting it with PGP. <h3>Input and Output</h3> <p>You are to write a program that will take in an arbitrary number of lines of text and output it in Pig Latin. Each line of text will contain one or more words. A ``word'' is defined as a consecutive sequence of letters (upper and/or lower case). Words should be converted to Pig Latin according to the following rules (non-words should be output exactly as they appear in the input): <ol> <li>Words that begin with a vowel (<tt>a</tt>, <tt>e</tt>, <tt>i</tt>, <tt>o</tt>, or <tt>u</tt>, and the capital versions of these) should just have the string ``<tt>ay</tt>'' (not including the quotes) appended to it. For example, ``<tt>apple</tt>'' becomes ``<tt>appleay</tt>''. <li>Words that begin with a consonant (any letter than is not <tt>A</tt>, <tt>a</tt>, <tt>E</tt>, <tt>e</tt>, <tt>I</tt>, <tt>i</tt>, <tt>O</tt>, <tt>o</tt>, <tt>U</tt> or <tt>u</tt>) should have the first consonant removed and appended to the end of the word, and then appending ``<tt>ay</tt>'' as well. For example, ``<tt>hello</tt>'' becomes ``<tt>ellohay</tt>''. <li>Do not change the case of any letter. </li> </ol> <h3>Sample Input</h3> <p> <pre>This is the input.</pre> <h3>Sample Output</h3> <p> <pre>hisTay isay hetay inputay.</pre> <p> </p> </div> <br>虽然题目隑ֺ不是很大Q但是对我启发挺大,到q种字符串处理的题,最好就是统一模式Q?br>                  a=getchar():<br>                   while(flag)<br>           {      while()//判断是否W合条g<br>                 { ----   ,<br>                        if((a=getchar())==EOF)//获取a=getchar()<br>                                  flag=0;//判断文g是否l束<br>                  }<br>                   while()//判断是否W合条g<br>                 { ----   ,<br>                        if((a=getchar())==EOF)//获取a=getchar()<br>                                  flag=0;//判断文g是否l束<br>                  }<br>              }<br> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">cstdlib</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br><br>  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br>  {<br> </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> freopen("s.txt","r",stdin);<br> </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> freopen("key.txt","w",stdout);</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> a;<br>  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,e</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,mark;<br>  </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> temp;<br>  </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000"> mar;<br>  a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">getchar();<br>  </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (e)<br>  {<br>           mark</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>            </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">((a</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">z</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">>=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">Z</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">))<br>          {<br>            temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ay</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br>             </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flag</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>            {<br>                 flag</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>                 </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">E</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">e</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">I</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">i</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">O</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">o</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">U</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">u</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br>                 cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">a;<br>                 </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> <br>                {<br>                    mark</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br>                    mar</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a;<br>                }<br>           }<br>            </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br>          cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">a;<br>          </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">((a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">getchar())</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">EOF)<br>                {<br>                    e</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>                    </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br>                 }    <br>         }<br>          </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(mark</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>           {<br>                cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">mar;<br>           }    <br>          cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">temp;<br>           </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">A</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">z</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">||</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">Z</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">a</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">))<br>           {<br>                cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">a;<br>                </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">((a</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">getchar())</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">EOF)<br>                {<br>                    e</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>                    </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br>                 }    <br>           } <br>           flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;   <br>  }<br>  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">system("PAUSE");</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">   </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>  }<br></span></div> <img src ="http://m.shnenglu.com/luyulaile/aggbug/89183.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-07-03 18:04 <a href="http://m.shnenglu.com/luyulaile/archive/2009/07/03/89183.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>joj 2197 perfect set 序偶对称http://m.shnenglu.com/luyulaile/archive/2009/07/03/89171.htmlluisluisFri, 03 Jul 2009 08:43:00 GMThttp://m.shnenglu.com/luyulaile/archive/2009/07/03/89171.htmlhttp://m.shnenglu.com/luyulaile/comments/89171.htmlhttp://m.shnenglu.com/luyulaile/archive/2009/07/03/89171.html#Feedback0http://m.shnenglu.com/luyulaile/comments/commentRss/89171.htmlhttp://m.shnenglu.com/luyulaile/services/trackbacks/89171.htmlA perfect point set is a set of points, for every point (x,y) in this set, point (y,x) is also in this set.

Input

There are mutical cases for this problem. For every input case, there is a set. we give you the number of points in this set in the first line, followed by n lines,each give two integers x y.

Output

If this set is a perfect set, you should print "Yes", else you print "No".

Sample Input

4
1 4
4 1
2 5
5 2

Sample Output

Yes
1Q这U类似稀疏矩늚数组对一般不用数l存储,用结构体比较?/pre>
2Q排序后比较非常的y妙?/pre>
#include<iostream>
#include<cstdlib>
using namespace std;
struct mm{
double a;
double b;}M[100000];
bool  operator<(mm m1,mm m2)
{
if(m1.a<m2.a)
return true;
else
{
if(m1.a==m2.a&&m1.b<m2.b)
return true;
}
return false;
}
int main()
{
// freopen("s.txt","r",stdin);
// freopen("key.txt","w",stdout);
int num;
double a,b;
int temp=0;
while(cin>>num)
{
memset(M,0,sizeof(M));
temp=0;
for(int k=0;k<num;k++)
{
cin>>a>>b;
if(a<b)
{
M[temp].a=a;
M[temp].b=b;
temp++;
}
else if(a>b)//把a和b相等的都L?
{
M[temp].a=b;
M[temp].b=a;
temp++;
}
}
if(temp%2!=0)cout<<"No"<<endl;
else
{
sort(M,M+temp);
int flag=0;
for(int p=0;p<temp;p+=2)
{
if(M[p].b!=M[p+1].b||M[p].a!=M[p+1].a)
{
flag=1;break;
}
}
if(flag==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
//system("PAUSE");
return   0;
}


luis 2009-07-03 16:43 发表评论
]]>joj 1157 Station Balance ?/title><link>http://m.shnenglu.com/luyulaile/archive/2009/07/01/88970.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Wed, 01 Jul 2009 02:54:00 GMT</pubDate><guid>http://m.shnenglu.com/luyulaile/archive/2009/07/01/88970.html</guid><wfw:comment>http://m.shnenglu.com/luyulaile/comments/88970.html</wfw:comment><comments>http://m.shnenglu.com/luyulaile/archive/2009/07/01/88970.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/luyulaile/comments/commentRss/88970.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/luyulaile/services/trackbacks/88970.html</trackback:ping><description><![CDATA[#include<iostream><br>#include<cstdlib><br>#include<iomanip><br>#include<algorithm> <br>#include<math.h><br>using namespace std;<br><br>  int main()<br>  {<br>//freopen("s.txt","r",stdin);<br>// freopen("key.txt","w",stdout);<br>  int n,m;<br>  int a[12];<br>  int time=0;<br>  while(cin>>n>>m)<br>  {<br>int i,j;<br>double k;<br>memset(a,0,sizeof(a));<br>time++;<br>double sum=0.0;<br>double temp=0.0;<br>for(i=0;i<m;i++)<br>{<br>cin>>a[i];<br>sum+=a[i];<br>}<br>sum/=n;<br>sort(a,a+2*n);//????a[0]????a[2n-1] <br>for(j=0;j<n;j++)<br>{<br>k=a[j]+a[2*n-j-1]-sum;<br>if(k>0)<br>        temp+=k;<br>    else<br>     temp-=k;<br>    }<br>    cout<<"Set #"<<time<<endl;<br>        cout<<"IMBALANCE = "<<fixed<<setprecision(5)<<temp<<endl<<endl;<br>  }<br><br>  //system("PAUSE");<br>  return   0;<br>  }<br>1Q设计到减法注意是否是doublecd<br>2Q要不要l对|abs(),include<math.h><br>3,cout<<fixed<<setprecision(5)能保障小数点后有Q?Q几位小? <img src ="http://m.shnenglu.com/luyulaile/aggbug/88970.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-07-01 10:54 <a href="http://m.shnenglu.com/luyulaile/archive/2009/07/01/88970.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://m.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.by8d5c.cn" target="_blank">þ97Ʒþþþþþò</a>| <a href="http://www.hbjyhg.cn" target="_blank">þav߳avav紵</a>| <a href="http://www.cnpump.com.cn" target="_blank">þþþavר</a>| <a href="http://www.playt.cn" target="_blank">þù㽶Ƶ</a>| <a href="http://www.xyftapp.cn" target="_blank">һaƬþëƬ</a>| <a href="http://www.syyinuo.cn" target="_blank">Ʒþ8xѹۿ</a>| <a href="http://www.czyhq.cn" target="_blank">aëƬþѲ</a>| <a href="http://www.fangfangmm.cn" target="_blank">99þùۺϾƷӰԺ</a>| <a href="http://www.ahozs.cn" target="_blank">99þþƷһëƬ</a>| <a href="http://www.lzjsyg.cn" target="_blank">ۺѾƷþþ</a>| <a href="http://www.ks29n.cn" target="_blank">һһþAþۺϾƷ</a>| <a href="http://www.jtuw.cn" target="_blank">һһþþƷۺ</a>| <a href="http://www.kuaixiansou.cn" target="_blank">þAVĻ</a>| <a href="http://www.fpzhan.cn" target="_blank">޺ݺݾþۺһ77777</a>| <a href="http://www.lntyyp.cn" target="_blank">͵͵þþþվ</a>| <a href="http://www.yizhu888.cn" target="_blank">ɫݺȷӰþ</a>| <a href="http://www.ding-u.cn" target="_blank">޾Ʒþþþȥq</a>| <a href="http://www.lordswar.cn" target="_blank">þþۺϾɫۺ98</a>| <a href="http://www.yiliaojiufen.cn" target="_blank">ٸۺϾþĻ</a>| <a href="http://www.taokecai.cn" target="_blank">þþƷһպ</a>| <a href="http://www.cnmere.cn" target="_blank">þþƷһ</a>| <a href="http://www.84993.com.cn" target="_blank">þùֱ</a>| <a href="http://www.y3d9.cn" target="_blank">ɫۺϾþ88ɫۺ</a>| <a href="http://www.aqbfrmi.cn" target="_blank">þþƷAVӰ</a>| <a href="http://www.badnao.cn" target="_blank">þþþþþþƷŮ99</a>| <a href="http://www.gcxd.net.cn" target="_blank">ҹӰþ</a>| <a href="http://www.dztd.gd.cn" target="_blank">۲ӰԺþ99</a>| <a href="http://www.cctyn.cn" target="_blank">Ʒ18þþþþvr</a>| <a href="http://www.car321.cn" target="_blank">99þþƷѿһ</a>| <a href="http://www.vrmn.cn" target="_blank">ھƷþþþþþ</a>| <a href="http://www.jrtz232.cn" target="_blank">þþþþAvӰԺ</a>| <a href="http://www.ppmm163.cn" target="_blank">þAAAƬ69</a>| <a href="http://www.zupy.cn" target="_blank">ƷþþĻһ</a>| <a href="http://www.auto-insurance.cn" target="_blank">þþ޹</a>| <a href="http://www.h21jc.cn" target="_blank">þ99ڹ</a>| <a href="http://www.xspree.cn" target="_blank">ٸ߳ҽоþþþþ</a>| <a href="http://www.010law.cn" target="_blank">þþƷ</a>| <a href="http://www.nxgy.net.cn" target="_blank">þۺɫˮ99ž</a>| <a href="http://www.shuntai.net.cn" target="_blank">aaþʦ2021Ʒ </a>| <a href="http://www.info88.cn" target="_blank">þպƬ</a>| <a href="http://www.122797929.cn" target="_blank">þþþۺĻ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>