Command and Rule over your Shell
Sultan now supports Python 2.7+ and 3.0+
Your input is welcome! Please provide your feedback by creatingissues on Github
pip install --upgrade sultan
Documentation is available on ReadTheDocs: http://sultan.readthedocs.io/en/latest/
Sultan is a Python package for interfacing with command-line utilities, likeyum, apt-get, or ls, in a Pythonic manner. It lets you run command-lineutilities using simple function calls.
The simplest way to use Sultan is to just call it:
from sultan.api import Sultan
s = Sultan()
s.sudo("yum install -y tree").run()
Runs:
sudo yum install -y tree;
The recommended way of using Sultan is to use it in Context Management mode.Here is how to use Sultan with Context Management:
from sultan.api import Sultan
with Sultan.load(sudo=True) as s:
s.yum("install -y tree").run()
Runs:
sudo su - root -c 'yum install -y tree;'
What if we want to install this command on a remote machine? You can easilyachieve this using context management:
from sultan.api import Sultan
with Sultan.load(sudo=True, hostname="myserver.com") as sultan:
sultan.yum("install -y tree").run()
Runs:
ssh root@myserver.com 'sudo su - root -c 'yum install -y tree;''
If you enter a wrong command, Sultan will print out details you need to debug andfind the problem quickly.
Here, the same command was run on a Mac:
from sultan.api import Sultan
with Sultan.load(sudo=True, hostname="myserver.com") as sultan:
sultan.yum("install -y tree").run()
Yields:
[sultan]: sudo su - root -c 'yum install -y tree;'
Password:
[sultan]: --{ STDERR }-------------------------------------------------------------------------------------------------------
[sultan]: | -sh: yum: command not found
[sultan]: -------------------------------------------------------------------------------------------------------------------
Want to get started? Simply install Sultan, and start writing your clean code:
pip install --upgrade sultan
If you have more questions, check the docs! http://sultan.readthedocs.io/en/latest/
链接:UVA167【The Sultan’s Successors】 题目描述: The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited
题目大意: 有若干模式串,将某些模式串拼接起来(一个可以使用多次)形成一个长模式串,判断能否有两种或更多种不同的拼法拼成相同的模式串。 思路: 神奇的构图,暴力的求解。 可以发现,若有不同的拼法,则一个模式串的前缀要与一个模式串的后缀相同。 因此我们就将问题转化成:从两个模式串开始,不停的按照前后缀匹配,最后达到两个串同时在一个点结束。 那么,将每一个串的每一个字符都看作一个点
The Sultan's Successors The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever per
题意与数据范围 给定一定长度的列表(以字符形式给出),你需要用 \(C\) 种颜色对每一对匹配的括号进行染色,两种方案被认为本质相同当且仅当在多次进行对任意一对括号内的元素全部平移一个单位的操作后,两个列表完全相同。求本质不同的染色方案数,答案对 \(10^9+7\) 取模 数据组数 \(T\le 4000\) ,\(C\le 100\) ,括号数 \(\le 200\) 这么描述题意比较抽象,我
//很久以前做的了,当时WA,一直没找到错误...然后今天看了下。。。发现就是每次开始新一轮年的时候没哟初始化....... The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each
HDOJ 1642 Problem Description The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever
题目链接:Uva 167 思路分析:八皇后问题,采用回溯法解决问题。 代码如下: #include <iostream> #include <string.h> using namespace std; const int MAX_N = 10; int A[MAX_N]; int M[MAX_N][MAX_N]; int num, Max = 0; int is_safe( int r
题目如下: The Sultan's Successors The Sultan of Nubia has no children, so she has decided that thecountry will be split into up to k separate parts on her death andeach part will be inherited by whoever
题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=103 题目描述: The Sultan's Successors The Sultan of Nubia has no children, so she has dec
The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever performs best at some test. I
The Sultan's Successors(八皇后问题) The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoev
General Sultan Input: Standard Input Output: Standard Output This is war time again! Our beloved Sultan has assumed the post of a general and going to the war with his huge army. Being an intelligen
最近备考蓝桥,学习到递归模块,从最基本的八皇后及其变种开始刷起(如果可以穿越,我一定要抓到发明递归的那个人,然后把他干掉,造福后世的算法er,)。 题目大意 一个人,没孩子,要在死前分割财产,然后出了一个题,让人们做,也就是八皇后,8 * 8 的棋盘,棋盘有64个值,不同的放置方案有不同的和,求最大的和就可得出答案。 心路历程 读懂题意后很容易看出来这是一道八皇后的变种题,因此做此题前一定要理解且
八王后问题,回溯算法 代码如下: #include <bits/stdc++.h> using namespace std; int number=0,x[10],y[100][10]; void D()//存储王后位置 { for(int i=1; i<=8; i++) y[number][i]=x[i]; number++; } int C(int n
The Sultan's Successors The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever perf
点击打开链接 这道题,明显就是八皇后问题 就是给你一个8*8的方格 问你找到八皇后占位置的 总和的最大值 这个题其实很简单 可以先开3个数组 来标记 一个标记 列 两个来标记 对角线 然后这道题深搜 就行了 其实对于行来说 直接就是 一行搜下来就行(因为一行肯定有一个皇后 来站着 ) 还有个坑点就是 我们这个要求 按着右边输出 右边输出就要(“%5d”) 我具体也不知道为什么 但是听
The Sultan of Nubia has no children, so she has decided that the country will be split into up to kseparate parts on her death and each part will be inherited by whoever performs best at some test
这道题是典型的八皇后问题,刘汝佳书上有具体的解说。 代码的实现例如以下: #include <stdio.h> #include <string.h> #include <stdlib.h> int vis[100][100];//刚開始wrong的原因就是这里数组开小了,开了[8][8],以为可以。后来看到[cur-i+8]意识到可能数组开小了。改大之后AC。 int a[8][8]; int
原题: The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever performs best at some tes
给出n个字符串,询问是否存在一个字符串(可以是给出的几个中的 也可以是组合成的),使得用字符串(随便你用多少个)来拼凑这个串,能够至少有两种拼法 解析: 把每一个字符串的每一个位置的字符看作结点,进行建边 两个字符串都刚好匹配完了,那就表明字符串i从s位置往后可以由j字符串组成,说明字符串i如果能匹配到s,那么就必然能匹配完,所以可以将id[i][s]这个点连向终点了 i字符串没匹配完,j字符
对每两个字符串进行匹配然后连边=看程序应该能看懂 开始st没清零不停地爆oj #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define rep(j,k,l) for (int j=k;j<=l;++j) #define M 25 #define N 110 #define P 2500
the squares thus selected sum to a number at least as high as one already chosen by the Sultan. (For those unfamiliar with the rules of chess, this implies that each row and column of the board contai
传送门UVa 167 - The Sultan's Successors 很经典很经典的八皇后问题,用LRJ老师书上的程序就可以解决。 其实我是被上两题逼得,只能拿这题先充数了TAT。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int vis[3][100], mmax; int
题目大意:给你一个 8 * 8 的棋盘,每个格子上面都有分数,求在上面放置 8 个皇后使棋盘的同一行、列、对角线上都只有一个皇后的可行方案中最高的分数 解题思路:这是一道 八皇后问题,只是多了个求最高分数,所以只需回溯查找出所有的可行方案中分数最高的即可 #include <cstdio> int board[8][8], vis[3][16] = {0}, max, t; void dfs(
这道题是典型的八皇后问题,刘汝佳书上有详细的讲解。代码的实现如下: #include <stdio.h> #include <string.h> #include <stdlib.h> int vis[100][100];//刚开始wrong的原因就是这里数组开小了,开了[8][8],以为能够。后来看到[cur-i+8]意识到可能数组开小了,改大之后AC。 int a[8][8]; int C[
题目大意:八皇后问题,每个格子有分数,皇后放置在格子上则得到分数,问怎么放置八皇后总分数最高。 解题思路:回溯,小紫里讲的挺清楚的,只要在达成条件时,将八个位置的分数加起来最后得到最高分输出就可以了。 ac代码: #include <iostream> using namespace std; int n, m, pos[8], sum, score[10][10]; void solve(int
UVA 167 The Sultan’s Successors 题目大意:类八皇后问题,每个格子都有权值 解题思路:回溯 #include <stdio.h> #include <iostream> #include <string.h> using namespace std; int num[9][9]; int ju[3][20]; int s; int p; void dfs(int a)
代码来源:DeathYmz AC的C++语言程序如下: #include<iostream> #include<cstdio> #include<cstring> using namespace std; //八皇后+回溯 int ans; int C[8]; int boards[8][8],vis[3][2*8]; void search(int cur)//问题只要求八个 cur行i
题目:八皇后问题的基础上输入每个格子上的数值。问哪一组数的和最小 #include <cstdio> #include <string.h> #include <cstdlib> #include <cmath> #include <ctgmath> #include <iostream> #include <vector> #include <algorithm> using namespace
这是一题八皇后的题,挺经典的。 给你一个k,表示有k组测试,接下来有8x8列,找出 最大皇后位置和最大 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> using namespace std; int p[9][9]; int vis[3][20]; int
The Sultan's Successors The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever per
题目: The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever performs best at some tes
题目例如以下: The Sultan's Successors The Sultan of Nubia has no children, so she has decided that thecountry will be split into up to k separate parts on her death andeach part will be inherited by whoeve
题意: 一串珍珠 可以从头或者尾偷窃 但要保证悬挂的珍珠的数量不变 珍珠保持悬挂状态要求重量满足题中的式子 问 最大偷窃多少价值 思路: 关注悬挂的珍珠 由于偷窃从头或者尾进行 所以末状态悬挂的珍珠一定是原串中一段连续的珍珠 那么如果知道悬挂的珍珠是哪一段 就可以利用二分查找桌上放多少珍珠能使得串不滑下去 这样二分的结果前面的珍珠就都可以偷 根据上述分析 可以枚举悬挂的珍珠
八皇后问题变形,参考算法竞赛入门P191页。 能过uva,过不了hdu…… 想想是不是还要第一次就走最大的那个格子…… #include "stdio.h" #include"string.h" //v保存每个格子价格,sum最后答案,vis0表示当前行,vis1表示i+j对角线,vis2表示j-i对角线 int v[10][10],sum,vis[2][25]; void dfs(int cu
就是八皇后问题 。。 题目: The Sultan's Successors The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited
167 - The Sultan's Successors Time limit: 3.000 seconds The Sultan of Nubia has no children, so she has decided that the country will be split into up to kseparate parts on her death and each part wil
The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever performs best at some test. I
The Sultan's Successors The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever per
The Sultan's Successors The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever perf
167 - The Sultan's Successors Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=103 The Sultan of Nubia has no child
经典八皇后问题变形,求出存在权值的情况下的最大值; // File Name: 1033.cpp // Author: bo_jwolf // Created Time: 2014年02月03日 星期一 18时37分57秒 #include<vector> #include<list> #include<map> #include<set> #include<deque> #include<s
题目167 - The Sultan's Successors 题目大意:就是八皇后的问题,只是加上求八个皇后所对应的位置对应的值相加的最大值。 阶梯思路:八皇后问题转换成全排列问题,C【i】 = j 表示第i行 的皇后在第j列,这样排列的话每行的皇后不会互相冲突,就需要判断每列的皇后和两条对角线是否有冲突的皇后,所以这需要开一个数组vis【3】【MAXN】, 每次判断vis【0】【j】(第j列有
题目大意: 有若干模式串,将某些模式串拼接起来(一个可以使用多次)形成一个长模式串,判断能否有两种或更多种不同的拼法拼成相同的模式串。 思路: 神奇的构图,暴力的求解。 可以发现,若有不同的拼法,则一个模式串的前缀要与一个模式串的后缀相同。 因此我们就将问题转化成:从两个模式串开始,不停的按照前后缀匹配,最后达到两个串同时在一个点结束。 那么,将每一个串的每一个字符都看作一个点
题目地址:点击打开链接 就是八皇后问题 #include <iostream> #include <cstring> #include <iomanip> using namespace std; int chess[8][8],visited[3][20]; int max_sum; void dfs(int cur,int sum) { if(cur==8) { if(sum>max_
题意与数据范围 给定一定长度的列表(以字符形式给出),你需要用 \(C\) 种颜色对每一对匹配的括号进行染色,两种方案被认为本质相同当且仅当在多次进行对任意一对括号内的元素全部平移一个单位的操作后,两个列表完全相同。求本质不同的染色方案数,答案对 \(10^9+7\) 取模 数据组数 \(T\le 4000\) ,\(C\le 100\) ,括号数 \(\le 200\) 这么描述题意比较抽象,我