Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

watery, use stringstream to process input, still 0ms

Posted by KatrineYang at 2016-09-13 11:02:04 on Problem 1304
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

int main() {
	while(1){
		string s;
		getline(cin, s);
		if(s == "ENDOFINPUT") break;
		stringstream ss;
		ss << s;
		string fei;
		int gs;
		ss >> fei >> gs;
		int mn = 2147483647;
		vector<int> dur[24];
		for(int i = 0; i < gs; i++){
			getline(cin, s);
			stringstream sss;
			sss << s;
			int temp;
			while(sss >> temp){
				dur[i].push_back(temp);
			}
		}
		getline(cin, s);
		stringstream ssss;
		ssss << s;
		int t;
		ssss >> t;
		getline(cin, s);
		for(int i = 0; i < gs; i++){
			int offset = 0;
			int sz = dur[i].size();
			int agg = 0;
			while(agg < t){
				agg += dur[i][offset];
				offset = (offset+1)%sz;
			}
			int deng = agg - t;
			if(deng < mn) mn = deng;
		}
		cout << mn << endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator