辽宁师范大学 • 张大为@https://daweizh.github.io/noip/

1.1 编程基础之输入输出(10)

  1. Hello,World!,http://noi.openjudge.cn/ch0101/01/
    #include <iostream>
    
    int main() {
        std::cout << "Hello, World!" << std::endl;
    
        return 0;
    }
    
  2. 输出第二个整数,http://noi.openjudge.cn/ch0101/02/
    #include <iostream>
    using namespace std;
    
    int main(){
        int a,b,c;
        
        cin >> a >> b >> c;
        cout << b << endl;
        
        return 0;
    }
    
  3. 对齐输出,http://noi.openjudge.cn/ch0101/03/
    #include <iostream>
    using namespace std;
    
    int main() {
        int a,b,c;
        
        cin >> a >> b >> c;
        printf("%8d %8d %8d",a,b,c);
    
        return 0;
    }
    
  4. 输出保留3位小数的浮点数,http://noi.openjudge.cn/ch0101/04/
    #include <iostream>
    using namespace std;
    
    int main() {
        float a;
        
        cin >> a ;
        printf("%.3f",a);
    
        return 0;
    }
    
  5. 输出保留12位小数的浮点数,http://noi.openjudge.cn/ch0101/05/
    #include <iostream>
    using namespace std;
    
    int main() {
        double a;
        
        cin >> a ;
        printf("%.12f",a);
    
        return 0;
    }
    
  6. 空格分隔输出,http://noi.openjudge.cn/ch0101/06/
    #include <iostream>
    using namespace std;
    
    int main() {
        char a;
        int b;
        float c;
        double d;
        
        cin >> a >> b >> c >> d;
        printf("%c %d %f %f",a,b,c,d);
    
        return 0;
    }
    
  7. 输出浮点数,http://noi.openjudge.cn/ch0101/07/
    #include <iostream>
    using namespace std;
    
    int main() {
        double a;
        
        cin >> a ;
        printf("%f\n",a);
        printf("%.5f\n",a);
        printf("%e\n",a);
        printf("%g\n",a);
    
        return 0;
    }
    
  8. 字符三角形,http://noi.openjudge.cn/ch0101/08/
    #include <iostream>
    using namespace std;
    
    int main(){
        char c;
        cin >> c;
        
        cout << "  " << c << endl;
        cout << " " << c << c << c << endl;
        cout << c << c << c << c << c << endl; 
        
        return 0;
    } 
    
  9. 字符菱形,http://noi.openjudge.cn/ch0101/09/
    #include <iostream>
    
    int main() {
        char ch;
        scanf("%c", &ch);
        printf("  %c\n",ch);
        printf(" %c%c%c\n",ch,ch,ch);
        printf("%c%c%c%c%c\n",ch,ch,ch,ch,ch);
        printf(" %c%c%c\n",ch,ch,ch);
        printf("  %c\n",ch);
        
        return 0;
    }
    
  10. 超级玛丽游戏,http://noi.openjudge.cn/ch0101/10/
    #include <iostream>
    using namespace std;
    
    int main(){
        cout << "                ********" << endl;
        cout << "               ************" << endl;
        cout << "               ####....#." << endl;
        cout << "             #..###.....##...." << endl;
        cout << "             ###.......######              ###                 ###           ###           ###" << endl;
        cout << "                ...........               #...#               #...#         #...#         #...#" << endl;
        cout << "               ##*#######                 #.#.#               #.#.#         #.#.#         #.#.#" << endl;
        cout << "            ####*******######             #.#.#               #.#.#         #.#.#         #.#.#" << endl;
        cout << "           ...#***.****.*###....          #...#               #...#         #...#         #...#" << endl;
        cout << "           ....**********##.....           ###                 ###           ###           ###" << endl;
        cout << "           ....****    *****...." << endl;
        cout << "             ####        ####" << endl;
        cout << "           ######        ######" << endl;
        cout << "##############################################################              ##################################" << endl;
        cout << "#...#......#.##...#......#.##...#......#.##------------------#              #...#......#.##------------------#" << endl;
        cout << "###########################################------------------#              ###############------------------#" << endl;
        cout << "#..#....#....##..#....#....##..#....#....#####################              #..#....#....#####################" << endl;
        cout << "##########################################    #----------#                  ##############    #----------#" << endl;
        cout << "#.....#......##.....#......##.....#......#    #----------#                  #.....#......#    #----------#" << endl;
        cout << "##########################################    #----------#                  ##############    #----------#" << endl;
        cout << "#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#                  #.#..#....#..#    #----------#" << endl;
        cout << "##########################################    ############                  ##############    ############" << endl;
    
        return 0;
    }
    

参考网址

  1. http://noi.openjudge.cn