哪种方式最适合排列右边的所有输出?
示例:for powers of 2:
class GameScene: SKScene {
@objc func slide(_ sender: UISwipeGestureRecognizer){
print("WORKS")
}
override func didMove(to view: SKView) {
let upSwipe = UISwipeGestureRecognizer(target: self, action: #selector(slide))
upSwipe.direction = .up
view.addGestureRecognizer(upSwipe)
}
}
如果我的最后一个号码有N个数字,那么如何打印第一个号码(在这种情况下只有一个数字),左边有(N-1)个空格?
答案 0 :(得分:4)
您可以使用printf()
向*
提供计算字段宽度。因此,在计算出最大位数后,您可以执行以下操作:
printf("%*d\n", max_digits, value);
答案 1 :(得分:2)
答案 2 :(得分:1)
实施例
But it seems they have differet way to show up, one of them is popup and another is change the css. If there is a way to combine them? I tried like
$(function () {
$('a[href="#search"]').on('click', function(event) {
event.preventDefault();
$('#search').addClass('open');
$.mobile.pageContainer.pagecontainer("getActivePage")
.addClass("blur-filter");
$('#search > form > input[type="search"]').focus();
});
$('#search, #search button.close').on('click keyup', function(event) {
if (event.target == this || event.target.className == 'close' || event.keyCode == 27) {
$(this).removeClass('open');
$(".blur-filter").removeClass("blur-filter");
}
});
//Do not include! This prevents the form from submitting for DEMO purposes only!
$('form').submit(function(event) {
event.preventDefault();
return false;
})
});
输出
int main(int argc, char *argv[]) {
for (int i=2; i<134217729;i=i*2)
printf("%*d\n",20, i);
return 0;
}