【语言】OJ编程题 Python C++常用输入模板

Python

# -*- coding:utf-8 -*-
import sys, os


class Solution:
    def do(self, ):
        return

if __name__ == '__main__':

    #  读取输入的一个整数,浮点数,字符/字符串, int, float, str
    v = int(sys.stdin.readline().strip())  # value

    # 读取输入的一行的两个整数,浮点数,字符/字符串
    n, m = list(map(str, sys.stdin.readline().strip().split(" ")))  # int, float, str

    # 读取输入的二维矩阵整数,浮点数,字符/字符串
    matrix = []
    for i in range(n):
        values = list(map(int, sys.stdin.readline().strip().split(" ")))  # int, float, str
        matrix.append(values)

    # 解决方案,自己添加需要传入的参数
    S = Solution()
    ret = S.do()  # matrix

    # 处理返回值
    if ret:
        print('true')
    else:
        print('false')

C++

 

#include <iostream>
#include <vector>
#include <string>
using namespace std;

class Solution1 {
public:
    bool Find() {
        return false;
    }
};


int main()
{
    int r, c;  // 一行输入两个数
    cin >> r >> c;

    string str;
    std::cin >> str;  // 一行输入y一个字符串

    // 输入r行,c列数据,存储到vector中
    vector<vector<int>> grid;
    int temp;
    for (int i = 0; i < r; i++)
    {
        vector<int> nums;
        for (int a = 0; a < c; a++)
        {
            cin >> temp;
            nums.push_back(temp);
        }
        grid.push_back(nums);
    }

    // 输入r行,c列数据,存储到数组中
    int **arr = new int*[r];
    for (int i = 0; i<r; i++)
        arr[i] = new int[c];
    for (int i = 0; i<r; i++)
        for (int j = 0; j<c; j++)
            cin >> arr[i][j];

    // while处理多个case
    while (cin >> str)
        std::cout << str << std::endl;

    // 以逗号为分隔符拆分字符串
    const char * split = ",";
    char *char_str = (char *)str.c_str();
    char *p = strtok(char_str, split);

    int a;
    vector<int> nums;
    while (p != NULL)
    {
        sscanf(p, "%d", &a);
        nums.push_back(a);
        p = strtok(NULL, split);
    }

    // 向解决方案函数传参
    Solution1 s = Solution1();
    bool t = s.Find();

    // 处理返回值
    if (t == 1)
        cout << "true";
    else
        cout << "false";
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值