zoukankan      html  css  js  c++  java
  • 1204. 错误票据(经典的输入处理方式)

    题目链接:

    https://www.acwing.com/problem/content/1206/

    题解:

    (1)getline()不会读 ,并且会抛弃读到的 ,而且不会留在缓冲区中。

    (2)cin不会读 ,但是会把它留在缓冲区中等其他人读入

    (3)stringstream在字符串、数字互转时很有用

    AC代码:

    #include<iostream>
    #include <sstream>
    #include <algorithm>
    #include <string>
    
    using namespace std;
    
    const int N = 10000+5;
    int a[N];
    int n;
    
    int main(){
        int cnt;
        cin >> cnt;
        string line;
        
        getline(cin,line);
        while(cnt--){
            getline(cin,line);
            stringstream ss(line);
            while(ss >> a[n]) n++;
        }
        
        
        stable_sort(a,a+n);
        int res1,res2;
        for(int i=1;i<n;i++){
            if(a[i] == a[i-1]) res2 = a[i];
            if(a[i] == a[i-1] + 2) res1 = a[i]-1;
        }
        
        cout << res1 << " " << res2 << endl;
        return 0;
    }
  • 相关阅读:
    装饰器
    深浅拷贝
    dm-开发知识片段积累
    java开发-SDE配置
    一、数据库介绍
    oracle学习 知识点目录
    五、Java SE核心II
    三、面向对象
    四、Java SE核心I
    二、Java语言基础
  • 原文地址:https://www.cnblogs.com/doubest/p/12297088.html
Copyright © 2011-2022 走看看