c++在线oj输入输出练习

c++在线oj输入输出练习

如何控制一行一行读取?cin.get() == ‘\n’

#include 
using namespace std;

int main() {
    int a;
    int sum = 0;
    while (cin >> a) { // 注意 while 处理多个 case
        sum += a;
        if(cin.get() == '\n'){
            cout<

如何判断当前字符是否为某个字符?cin.get(c);

#include 
#include 
#include 
#include 
using namespace std;
int main() {
    string s;
    vector ss;
    char ch;
    string temp;
    while(cin.get(ch)){
        if(ch == ','){
            ss.push_back(temp);
            temp.clear();
            continue;
        }
        else if(ch == '\n'){
            ss.push_back(temp);
            temp.clear();
            sort(ss.begin(),ss.end());
            for(auto iter = ss.begin();iter!=ss.end();iter++){
                if(iter!=ss.end()-1){
                    cout<<*iter<<",";
                }
                else{
                    cout<<*iter<

参考文献

[1] https://www.nowcoder.com/exam/test/71420049/detail?pid=27976983#question OJ在线编程常见输入输出练习。

你可能感兴趣的:(c++,算法,开发语言)