求离散数学c++代码,把一个序偶关系转换为关系矩阵,例如输入;;;;;会输出对应的关系矩阵
1条回答 默认 最新
- threenewbee 2016-05-16 14:37关注
用C#写一个给你
using System; using System.Linq; public class Test { public static void Main() { // your code goes here string s = "<a,b>;<b,c>;<a,d>;<c,e>;<e,a>;<d,b>"; int n = s.Where(x => x >= 'a' && x <= 'z').Max() - 'a' + 1; int[,] arr = new int[n, n]; foreach (var item in s.Split(';').Select(x => new { a = x[1] - 'a', b = x[3] - 'a' })) { arr[item.a, item.b] = 1; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Console.Write(arr[i, j] + "\t"); } Console.WriteLine(); } } }
0 1 0 1 0
0 0 1 0 0
0 0 0 0 1
0 1 0 0 0
1 0 0 0 0解决 无用评论 打赏 举报
悬赏问题
- ¥15 虚拟机打包apk出现错误
- ¥30 最小化遗憾贪心算法上界
- ¥15 用visual studi code完成html页面
- ¥15 聚类分析或者python进行数据分析
- ¥15 逻辑谓词和消解原理的运用
- ¥15 三菱伺服电机按启动按钮有使能但不动作
- ¥15 js,页面2返回页面1时定位进入的设备
- ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
- ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
- ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝