problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
acwing::acwing4304类 参考

AcWing 4304. 字符串归类 更多...

#include <acwing.h>

静态 Public 成员函数

static int main (istream &cin, ostream &cout)
 
static unsigned int str2int (const string &str)
 

详细描述

AcWing 4304. 字符串归类

在文件 acwing.h1327 行定义.

成员函数说明

◆ main()

int acwing::acwing4304::main ( istream &  cin,
ostream &  cout 
)
static

在文件 acwing.cpp4289 行定义.

4289 {
4290 int n;
4291 cin >> n;
4292 auto vec = vector<unsigned int>();
4293 for(int i = 0; i < n; i++) {
4294 string str;
4295 cin >> str;
4296 auto ui = str2int(str);
4297 bool flag = false;
4298 for(int j = 0; j < vec.size(); j++) {
4299 if((vec[j] & ui) != 0) {
4300 vec[j] |= ui;
4301 flag = true;
4302 }
4303 }
4304 if(!flag) {
4305 vec.push_back(ui);
4306 }
4307 }
4308 bool ok = true;
4309 while(ok) {
4310 ok = false;
4311 for(int i = 0; i + 1 < vec.size(); i++) {
4312 for(int j = i + 1; j < vec.size(); j++) {
4313 if((vec[i] & vec[j]) != 0) {
4314 vec[i] |= vec[j];
4315 vec.erase(vec.begin() + j);
4316 ok = true;
4317 }
4318 }
4319 }
4320 }
4321 cout << vec.size();
4322 return 0;
4323 }
int vec[100010]
Definition: pat.cpp:5095
static unsigned int str2int(const string &str)
Definition: acwing.cpp:4325

被这些函数引用 acwing::TEST().

◆ str2int()

unsigned int acwing::acwing4304::str2int ( const string &  str)
static

在文件 acwing.cpp4325 行定义.

4325 {
4326 unsigned int ans = 0;
4327 for(const char ch: str) {
4328 ans |= 1 << ch - 'a';
4329 }
4330 return ans;
4331 }

该类的文档由以下文件生成: