关于c/c++编辑代码时的换行问题(noip1.1输出超级玛丽)
c、c++写代码时,并不需要这么严谨,如一条printf()函数语句就写在一行,很多语句是可以用换行从中间断开的。
如下面的例子完全可以正常运行,和规矩写法无异。
当然也有例外
1.关键字内部不能换行如int不能写成in
t
2.字符串,字符串如scanf,printf和cout中使用的字符串,"1234"不能直接断开,但可以在字符串需要断开处加个\然后换行,字符串就会接着下一行的开头。
如经典超级玛丽题目可以如第二个代码所示这样写。
把整个复制过来后,每行后面加\n\,最后一行加\。
比每行都复制过来用一条printf输出简单。并且代码中最大程度地保留了超级玛丽的图样,简洁优美。
#include <stdio.h> #include<ctype.h> #include <string.h> #include<iostream> using namespace std; int main ( ) { int a ; printf ("123" ); cout<<"123" ; scanf("%d" , & a ) ; return 0; }
代码二
#include<cstdio> int main() { printf("\ ********\n\ ************\n\ ####....#.\n\ #..###.....##....\n\ ###.......###### ### ### ### ###\n\ ........... #...# #...# #...# #...#\n\ ##*####### #.#.# #.#.# #.#.# #.#.#\n\ ####*******###### #.#.# #.#.# #.#.# #.#.#\n\ ...#***.****.*###.... #...# #...# #...# #...#\n\ ....**********##..... ### ### ### ###\n\ ....**** *****....\n\ #### ####\n\ ###### ######\n\ ############################################################## ##################################\n\ #...#......#.##...#......#.##...#......#.##------------------# #...#......#.##------------------#\n\ ###########################################------------------# ###############------------------#\n\ #..#....#....##..#....#....##..#....#....##################### #..#....#....#####################\n\ ########################################## #----------# ############## #----------#\n\ #.....#......##.....#......##.....#......# #----------# #.....#......# #----------#\n\ ########################################## #----------# ############## #----------#\n\ #.#..#....#..##.#..#....#..##.#..#....#..# #----------# #.#..#....#..# #----------#\n\ ########################################## ############ ############## ############\ "); return 0; }