当前位置:码农谷 > 算法与程序 > POJ 2269 Friends:题目解答源码

POJ 2269 Friends:题目解答源码

所属学科:C语言 - 编译预处理 难度: 关注度:20

You want to plan a big birthday party with your friends. On planning you notice that you have to do a lot of operations with sets of friends. There is one group which consist of Arthur, Biene and Clemens. Then there is a group of friends you know from snowboarding which consists of Daniel, Ernst, Frida and Gustav. If you want to invite them both, the resulting party group consists of g1 + g2 (the result is the union of both groups). Then you can compute the intersection of the two groups g1 * g2, which consists of the empty set. Maybe you want to invite a group g1, but excluding all members of an other group g2, which is written as g1 - g2.
Intersection (*) has precedence over union (+) and set difference (-). All operations are left associative, which means that in A op1 B op2 C you first have to evaluate A op1 B (provided op1 and op2 have equal precedence).

输入描述

The input consists of one or more lines. Each line contains one expression that you have to evaluate. Expressions are syntactically correct and only consist of the characters:

'{' and '}'

the elements 'A' to 'Z' meaning friend Arthur to Zora.

the operations '+', '-' and '*'

'(' and ')' for grouping operations

the newline character '\n' marking the end of an expression.

A line is never longer than 255 characters.

输出描述

Output the resulting set in curly braces '{' and '}', each on a line of its own. Print elements of sets sorted alphabetically.

程序源码

完整的源代码如下:

#include "iostream"
#include "stdio.h"
#include "string.h"
#include"stack"
using namespace std;
char s[100008];
int id;
struct point{
    int c[26];
    point(){ memset(c,0,sizeof(c)); }
    point operator + (const point &p1)
    {
        point temp;
        for(int i=0;i<26;i++) temp.c[i]=c[i]|p1.c[i];
        return temp;
    }
    point operator - (const point &p1)
    {
        point temp;
        for(int i=0;i<26;i++) temp.c[i]=c[i]&(!p1.c[i]);

关注微信,获得更多免费资源
关于我们   |   免责声明   |   联系我们   |   网站地图   |   HR交流群   |   学生交流群   |   教师交流群

码农谷   版权所有 © 2015-2017   湘ICP备16018319号-1