C++分析产品功能数据生成markdown表格代码

代码功能描述:

 

将各自产品支持的各自功能或特性汇总成一张2维大表. 参考下面的输入输出样例.

目录

源代码

输入样例

输出样例

粘贴到MarkDown工具内

快速运行


源代码

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

typedef string TYPE;
typedef string ITEM;
int main()
{
	string type;
	vector<TYPE> typelist;
	vector<ITEM> allitemlist;
	vector<ITEM> typeitemlist;
	map<TYPE, vector<string>> mp;
	while(cin>>type){
		if(type == "-1")
			break;
		typelist.push_back(type);
		string item;
		while(cin>>item){
			if(item=="-1")
				break;
			if(find(allitemlist.begin(), allitemlist.end(), item)==allitemlist.end())
				allitemlist.push_back(item);
			typeitemlist.push_back(item);
		}
		mp[type]=(typeitemlist);
		typeitemlist.clear();
	}
    // 输出表头
    cout << "|   |";
    for(vector<TYPE>::iterator it = typelist.begin(); it!=typelist.end(); it++)
        cout << *it << " |";	
    cout << endl;
    cout << "|---|";
    for(vector<TYPE>::iterator it = typelist.begin(); it!=typelist.end(); it++)
        cout << "---|";	
    cout << endl;
    // 输出表主体
    for(vector<ITEM>::iterator it = allitemlist.begin(); it!=allitemlist.end(); it++){
        cout << "| " << *it << " |";
        for(vector<TYPE>::iterator tp = typelist.begin(); tp!= typelist.end(); tp++){
            if ( std::find(mp[*tp].begin(), mp[*tp].end(), *it) != mp[*tp].end() )
                cout << " True" << " |";	
            else
                cout << "    " << " |";	
        }
        cout << endl;
    }
}

输入样例

[产品甲]
A功能
B功能
C功能
D功能
-1
[产品乙]
B功能
F功能
c功能
-1
[产品丁]
C功能
G功能
-1
-1

输出样例

|   |[产品甲] |[产品乙] |[产品丁] |
|---|---|---|---|
| A功能 | True |     |     |
| B功能 | True | True |     |
| C功能 | True |     | True |
| D功能 | True |     |     |
| F功能 |     | True |     |
| c功能 |     | True |     |
| G功能 |     |     | True |

粘贴到MarkDown工具内

快速运行

C++ 在线工具 | 菜鸟工具 (runoob.com)

数据很多的话, 上面那个工具就失效了. 可以用下面的链接:

Online C++ Compiler - online editor (onlinegdb.com)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值