通常对于普通函数来说,要访问类的保护成员是不可能的,如果想这么做那么必须把类的成员都生命成为public(共用的),然而这做带来的问题遍是任何外部函数都可以毫无约束的访问它操作它,c++利用friend修饰符,可以让一些你设定的函数能够对这些保护数据进行操作,避免把类成员全部设置成public,最大限度的保护数据成员的安全。 友元能够使得普通函数直接访问类的保护数据,避免了类成员函数的频繁调用,可...
                            
                            
                                分类:
编程语言   时间:
2014-08-04 18:03:27   
                                阅读次数:
226
                             
                    
                        
                            
                            
                                题目链接:UVa12726是个PDF,不好复制进来。大意:有个人要追个妹子,想加妹子QQ,但是不知道谁规定的,玩QQ的人要加好友必须先要有至少k个共同好友。共有N个人玩QQ,编号为1到N,1是男主,N是妹子。有M个初始好友关系,求男主最少要加多少个人才能有资格加妹子,或者永远加不到妹子。题解:最少加...
                            
                            
                                分类:
其他好文   时间:
2014-08-04 13:27:27   
                                阅读次数:
338
                             
                    
                        
                            
                            
                                //25...9.4.
//4.71.3..6
//8.34.759.
//3.8.7..69
//.1.3.24..
//5.49.6.83
//9.6.3.7.8
//.3.6.8.1.
//1.2.9.6.4
struct node
{
    node(int r,int c):row(r),col(c) {}
    friend ostream& operator <<(ostr...
                            
                            
                                分类:
其他好文   时间:
2014-08-02 15:31:53   
                                阅读次数:
272
                             
                    
                        
                            
                            
                                STL实现优先队列
使用方法:
头文件:
#include 
声明方式:
priority_queueq;
结构体的声明方式:
struct node
{
      int x, y;
       friend bool operator  b.x; //结构体中,x小的优先级高
      }
};...
                            
                            
                                分类:
其他好文   时间:
2014-08-01 13:52:41   
                                阅读次数:
186
                             
                    
                        
                            
                            
                                SuperMemoTime Limit: 5000MSMemory Limit: 65536KCase Time Limit: 2000MSDescriptionYour friend, Jackson is invited to a TV show called SuperMemo in whic...
                            
                            
                                分类:
其他好文   时间:
2014-07-31 16:30:07   
                                阅读次数:
404
                             
                    
                        
                            
                            
                                欧几里得- -要分N种情况- -#include#includeusing namespace std;int gcd(int x,int y){if (y==0) return x;return gcd(y,x%y);}struct node{ int x,y; friend ...
                            
                            
                                分类:
其他好文   时间:
2014-07-31 16:18:27   
                                阅读次数:
156
                             
                    
                        
                            
                            
                                LOOPS
Problem Description
Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl).
Homura wants to help her friend Madoka save the world. But because of the plot of the Boss Incubator, ...
                            
                            
                                分类:
其他好文   时间:
2014-07-31 13:31:27   
                                阅读次数:
232
                             
                    
                        
                            
                            
                                Sales_item.h#ifndef SALES_ITEM_H#define SALES_ITEM_H#include#includeusing namespace std;class Sales_item{ friend ostream& operator>(istream &is,Sal...
                            
                            
                                分类:
其他好文   时间:
2014-07-31 09:37:26   
                                阅读次数:
237
                             
                    
                        
                            
                            
                                Description
On Saint Valentine's Day, Alex imagined to present a special pendant to his girl friend made by K kind of pearls. The pendant is actually a string of pearls, and its length is defined a...
                            
                            
                                分类:
其他好文   时间:
2014-07-30 17:30:44   
                                阅读次数:
349
                             
                    
                        
                            
                            
                                Problem Description
Recently, Doge got a funny birthday present from his new friend, Protein Tiger from St. Beeze College. No, not cactuses. It's a mysterious blackbox.
After some research, Doge...
                            
                            
                                分类:
其他好文   时间:
2014-07-30 17:27:44   
                                阅读次数:
282