1056: 邻接表到邻接矩阵

解法:

cpp 复制代码
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int arr[100][100];
int main() {
	int n;
	cin >> n;
	getchar();
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		getline(cin, s[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < s[i].size(); j++) {
			if (s[i][j] >= '0' && s[i][j] <= '9') {
				arr[i][s[i][j]-'0'] = 1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << arr[i][j];
		}
		cout << endl;
	}
	return 0;
}
相关推荐
Sam_Deep_Thinking19 小时前
学数据结构到底有什么用
数据结构
kobesdu19 小时前
人形机器人SLAM:技术挑战、算法综述与开源方案
算法·机器人·人形机器人
椰羊~王小美21 小时前
随机数概念及算法
算法
阿Y加油吧21 小时前
算法实战笔记:LeetCode 169 多数元素 & 75 颜色分类
笔记·算法·leetcode
不要秃头的小孩21 小时前
力扣刷题——509. 斐波那契数
python·算法·leetcode·动态规划
We་ct1 天前
LeetCode 120. 三角形最小路径和:动态规划详解
前端·javascript·算法·leetcode·typescript·动态规划
py有趣1 天前
力扣热门100题之和为K的子数组
数据结构·算法·leetcode
hipolymers1 天前
C语言怎么样?难学吗?
c语言·数据结构·学习·算法·编程
CS创新实验室1 天前
从“跑得动”到“跑得稳”:深度剖析数据结构究竟是理论点缀还是核心战力?
数据结构