output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <iostream> #include <sstream> #include <cstdio> #include <cstdlib> #include <cmath> #include <ctime> #include <cstring> #include <string> #include <vector> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <numeric> #include <utility> #include <iomanip> #include <algorithm> #include <functional> using namespace std; typedef long long ll; typedef vector<int> vint; typedef vector<ll> vll; typedef pair<int,int> pint; #define DE 1 #define FI first #define SE second #define PB push_back #define MP make_pair #define ALL(s) (s).begin(),(s).end() #define REP(i,n) for (int i = 0; i < (int)(n); ++i) #define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i) #define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';} template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;} template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;} int A, B, K; vector<int> tovec(long long a, int n) { vector<int> res; while (true) { if (a < n) { res.push_back(a); break; } else { res.push_back((int)(a%n)); a /= n; } } return res; } long long tonum(vector<int> P, int n) { long long res = 0LL; reverse(ALL(P)); for (int i = 0; i < P.size(); ++i) { res *= (long long)(n); res += (long long)(P[i]); } return res; } vint sub(vint va, vint vb, int bit) { int n = va.size(); vint res(n, 0); int b = 0; for (int i = 0; i < n-1; ++i) { if (bit & (1<<i)) { if (va[i]-b >= vb[i]) return vint(); res[i] = va[i] + 10 - vb[i] - b; b = 0; } else { if (va[i]-b >= vb[i]) { res[i] = va[i] - vb[i] - b; b = 0; } else { res[i] = va[i] + 10 - vb[i] - b; b = 1; } } } return res; } int main() { while (cin >> A >> B >> K) { int res = -1; vint va = tovec(A, 10), vb = tovec(B, 10); while (va.size() < 10) va.PB(0); while (vb.size() < 10) vb.PB(0); //COUT(va); COUT(vb); for (int bit = 0; bit < (1<<10); ++bit) { if (__builtin_popcount(bit) > K) continue; vint vt = sub(va, vb, bit); //cout << bitset<5>(bit) << " : " << vt; int t = tonum(vt, 10); res = max(res, t); } cout << res << endl; } return 0; }
### Prompt Please provide a Cpp coded solution to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <sstream> #include <cstdio> #include <cstdlib> #include <cmath> #include <ctime> #include <cstring> #include <string> #include <vector> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <numeric> #include <utility> #include <iomanip> #include <algorithm> #include <functional> using namespace std; typedef long long ll; typedef vector<int> vint; typedef vector<ll> vll; typedef pair<int,int> pint; #define DE 1 #define FI first #define SE second #define PB push_back #define MP make_pair #define ALL(s) (s).begin(),(s).end() #define REP(i,n) for (int i = 0; i < (int)(n); ++i) #define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i) #define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';} template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;} template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;} int A, B, K; vector<int> tovec(long long a, int n) { vector<int> res; while (true) { if (a < n) { res.push_back(a); break; } else { res.push_back((int)(a%n)); a /= n; } } return res; } long long tonum(vector<int> P, int n) { long long res = 0LL; reverse(ALL(P)); for (int i = 0; i < P.size(); ++i) { res *= (long long)(n); res += (long long)(P[i]); } return res; } vint sub(vint va, vint vb, int bit) { int n = va.size(); vint res(n, 0); int b = 0; for (int i = 0; i < n-1; ++i) { if (bit & (1<<i)) { if (va[i]-b >= vb[i]) return vint(); res[i] = va[i] + 10 - vb[i] - b; b = 0; } else { if (va[i]-b >= vb[i]) { res[i] = va[i] - vb[i] - b; b = 0; } else { res[i] = va[i] + 10 - vb[i] - b; b = 1; } } } return res; } int main() { while (cin >> A >> B >> K) { int res = -1; vint va = tovec(A, 10), vb = tovec(B, 10); while (va.size() < 10) va.PB(0); while (vb.size() < 10) vb.PB(0); //COUT(va); COUT(vb); for (int bit = 0; bit < (1<<10); ++bit) { if (__builtin_popcount(bit) > K) continue; vint vt = sub(va, vb, bit); //cout << bitset<5>(bit) << " : " << vt; int t = tonum(vt, 10); res = max(res, t); } cout << res << endl; } return 0; } ```
#include <iostream> using namespace std; int solve(const int *a, const int *b, int s) { int c[10] = {0}; int borrow = 0; for (int i = 0; i < 10; i++) { if (a[i] - borrow >= b[i]) { c[i] = a[i] - borrow - b[i]; borrow = 0; } else { c[i] = a[i] - borrow + 10 - b[i]; if (s & (1<<i)) { borrow = 0; } else { borrow = 1; } } } int n = 0; for (int i = 9; i >= 0; i--) { n = 10*n + c[i]; } return n; } int main() { int A, B, K; cin >> A >> B >> K; int a[10], b[10]; for (int i = 0; i < 10; i++) { a[i] = A%10; b[i] = B%10; A /= 10; B /= 10; } int ans = 0; for (int s = 0; s < (1<<9); s++) { if (__builtin_popcount(s) <= K) { ans = max(ans, solve(a, b, s)); } } cout << ans << endl; return 0; }
### Prompt Please provide a CPP coded solution to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> using namespace std; int solve(const int *a, const int *b, int s) { int c[10] = {0}; int borrow = 0; for (int i = 0; i < 10; i++) { if (a[i] - borrow >= b[i]) { c[i] = a[i] - borrow - b[i]; borrow = 0; } else { c[i] = a[i] - borrow + 10 - b[i]; if (s & (1<<i)) { borrow = 0; } else { borrow = 1; } } } int n = 0; for (int i = 9; i >= 0; i--) { n = 10*n + c[i]; } return n; } int main() { int A, B, K; cin >> A >> B >> K; int a[10], b[10]; for (int i = 0; i < 10; i++) { a[i] = A%10; b[i] = B%10; A /= 10; B /= 10; } int ans = 0; for (int s = 0; s < (1<<9); s++) { if (__builtin_popcount(s) <= K) { ans = max(ans, solve(a, b, s)); } } cout << ans << endl; return 0; } ```
#include <bits/stdc++.h> using namespace std; int a[11] = {0}, b[11] = {0}; int K; int solve(int idx, int k, int brw) { if(k < 0) return -(1 << 25); if(idx == 0) return 0; int sa = a[idx] - b[idx]; int ret = -(1 << 25); if(brw == 1) sa--; if(sa < 0){ if(k > 0) ret = solve(idx-1, k-1, 0) + (sa+10) * pow(10, 10-idx); ret = max(ret, solve(idx-1, k, 1) + (sa+10) * (int)pow(10, 10-idx)); } else { ret = solve(idx-1, k, 0) + sa * pow(10, 10-idx); } return ret; } int main() { string A, B; cin >> A >> B >> K; for(int i = A.size() - 1, j = 10; i >= 0; i--, j--){ a[j] = A[i] - '0'; } for(int i = B.size() - 1, j = 10; i >= 0; i--, j--){ b[j] = B[i] - '0'; } cout << solve(10, K, 0) << endl; return 0; }
### Prompt In cpp, your task is to solve the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int a[11] = {0}, b[11] = {0}; int K; int solve(int idx, int k, int brw) { if(k < 0) return -(1 << 25); if(idx == 0) return 0; int sa = a[idx] - b[idx]; int ret = -(1 << 25); if(brw == 1) sa--; if(sa < 0){ if(k > 0) ret = solve(idx-1, k-1, 0) + (sa+10) * pow(10, 10-idx); ret = max(ret, solve(idx-1, k, 1) + (sa+10) * (int)pow(10, 10-idx)); } else { ret = solve(idx-1, k, 0) + sa * pow(10, 10-idx); } return ret; } int main() { string A, B; cin >> A >> B >> K; for(int i = A.size() - 1, j = 10; i >= 0; i--, j--){ a[j] = A[i] - '0'; } for(int i = B.size() - 1, j = 10; i >= 0; i--, j--){ b[j] = B[i] - '0'; } cout << solve(10, K, 0) << endl; return 0; } ```
#include<iostream> #include<algorithm> #include<cstring> #define N 99999 using namespace std; int main(){ int A[N],B[N],C_0[N],C_1[N],K; string a,b; cin >> a >> b >> K; memset(A,0,sizeof(A)); memset(B,0,sizeof(B)); memset(C_0,0,sizeof(C_0)); memset(C_1,0,sizeof(C_1)); int hh=0; for(int i=a.length()-1;i>=0;i--){ A[i] = a[(a.length()-1)-i] - '0'; if(i >= b.length()){ B[i] = 0; hh++; } else B[i] = b[(a.length()-1)-i-hh] - '0'; } int br[N]; br[0] = 0; for(int i=0;i<a.length();i++) { //cout << "br[" << i << "] = " << br[i] << endl; if(br[i] == 0) { if(A[i] - 0 >= B[i]){ C_0[i] = A[i] - 0 - B[i]; br[i+1]=0; }else if(A[i] - 0 < B[i]){ C_0[i] = A[i] - 0 + 10 - B[i]; br[i+1]=1; } if(A[i] - 1 >= B[i]){ C_1[i] = A[i] - 1 - B[i]; }else if(A[i] - 1 < B[i]){ C_1[i] = A[i] - 1 + 10 - B[i]; } } else if(br[i] == 1) { if(A[i] - 0 >= B[i]){ C_0[i] = A[i] - 0 - B[i]; }else if(A[i] - 0 < B[i]){ C_0[i] = A[i] - 0 + 10 - B[i]; } if(A[i] - 1 >= B[i]){ C_1[i] = A[i] - 1 - B[i]; br[i+1] = 0; }else if(A[i] - 1 < B[i]){ C_1[i] = A[i] - 1 + 10 - B[i]; br[i+1] = 1; } } //cout << "C_0[" << i << "] = " << C_0[i] << endl; //cout << "C_1[" << i << "] = " << C_1[i] << endl; } int fl=0; for(int i=a.length()-1;i>=0;i--){ if(br[i] == 1 && C_0[i] > C_1[i] && K > 0){ if(C_0[i] == 0 && fl == 0) continue; else { fl = 1; cout << C_0[i]; K--; } }else if(br[i] == 1){ if(C_1[i] == 0 && fl ==0) continue; else { fl =1; cout << C_1[i]; } } else if(br[i] == 0){ if(C_0[i] == 0 && fl == 0)continue; else{ cout << C_0[i]; fl = 1; } } } cout <<endl; }
### Prompt Construct a CPP code solution to the problem outlined: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<iostream> #include<algorithm> #include<cstring> #define N 99999 using namespace std; int main(){ int A[N],B[N],C_0[N],C_1[N],K; string a,b; cin >> a >> b >> K; memset(A,0,sizeof(A)); memset(B,0,sizeof(B)); memset(C_0,0,sizeof(C_0)); memset(C_1,0,sizeof(C_1)); int hh=0; for(int i=a.length()-1;i>=0;i--){ A[i] = a[(a.length()-1)-i] - '0'; if(i >= b.length()){ B[i] = 0; hh++; } else B[i] = b[(a.length()-1)-i-hh] - '0'; } int br[N]; br[0] = 0; for(int i=0;i<a.length();i++) { //cout << "br[" << i << "] = " << br[i] << endl; if(br[i] == 0) { if(A[i] - 0 >= B[i]){ C_0[i] = A[i] - 0 - B[i]; br[i+1]=0; }else if(A[i] - 0 < B[i]){ C_0[i] = A[i] - 0 + 10 - B[i]; br[i+1]=1; } if(A[i] - 1 >= B[i]){ C_1[i] = A[i] - 1 - B[i]; }else if(A[i] - 1 < B[i]){ C_1[i] = A[i] - 1 + 10 - B[i]; } } else if(br[i] == 1) { if(A[i] - 0 >= B[i]){ C_0[i] = A[i] - 0 - B[i]; }else if(A[i] - 0 < B[i]){ C_0[i] = A[i] - 0 + 10 - B[i]; } if(A[i] - 1 >= B[i]){ C_1[i] = A[i] - 1 - B[i]; br[i+1] = 0; }else if(A[i] - 1 < B[i]){ C_1[i] = A[i] - 1 + 10 - B[i]; br[i+1] = 1; } } //cout << "C_0[" << i << "] = " << C_0[i] << endl; //cout << "C_1[" << i << "] = " << C_1[i] << endl; } int fl=0; for(int i=a.length()-1;i>=0;i--){ if(br[i] == 1 && C_0[i] > C_1[i] && K > 0){ if(C_0[i] == 0 && fl == 0) continue; else { fl = 1; cout << C_0[i]; K--; } }else if(br[i] == 1){ if(C_1[i] == 0 && fl ==0) continue; else { fl =1; cout << C_1[i]; } } else if(br[i] == 0){ if(C_0[i] == 0 && fl == 0)continue; else{ cout << C_0[i]; fl = 1; } } } cout <<endl; } ```
#include<stdio.h> #include<algorithm> using namespace std; int ret; int A[11]; int B[11]; int C[11]; int n; void solve(int a,int b,int c){ if(a==n){ int tmp=0; for(int i=10;i>=0;i--){ tmp*=10;tmp+=C[i]; } ret=max(ret,tmp); return; } int t=A[a]-B[a]-b; if(t<0){ C[a]=t+10; if(c)solve(a+1,0,c-1); solve(a+1,1,c); }else{ C[a]=t; solve(a+1,0,c); } } int main(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); int at=0; while(a){ A[at]=a%10; a/=10;at++; } n=at; at=0; while(b){ B[at]=b%10;b/=10;at++; } solve(0,0,c); printf("%d\n",ret); }
### Prompt In CPP, your task is to solve the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<stdio.h> #include<algorithm> using namespace std; int ret; int A[11]; int B[11]; int C[11]; int n; void solve(int a,int b,int c){ if(a==n){ int tmp=0; for(int i=10;i>=0;i--){ tmp*=10;tmp+=C[i]; } ret=max(ret,tmp); return; } int t=A[a]-B[a]-b; if(t<0){ C[a]=t+10; if(c)solve(a+1,0,c-1); solve(a+1,1,c); }else{ C[a]=t; solve(a+1,0,c); } } int main(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); int at=0; while(a){ A[at]=a%10; a/=10;at++; } n=at; at=0; while(b){ B[at]=b%10;b/=10;at++; } solve(0,0,c); printf("%d\n",ret); } ```
#include <stdio.h> #include <cmath> #include <algorithm> #include <cfloat> #include <stack> #include <queue> #include <vector> typedef long long int ll; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000001 using namespace std; int main(){ int K,A[11],B[11],C[11],ans,tmp_digit,POW[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000}; char buf_A[11],buf_B[11]; stack<int> S; for(int i = 0; i <= 10; i++){ A[i] = 0; B[i] = 0; } scanf("%s %s %d",buf_A,buf_B,&K); int a_length,b_length; for(a_length = 0; buf_A[a_length] != '\0'; a_length++); for(b_length = 0; buf_B[b_length] != '\0'; b_length++); for(int i = 0;i < a_length; i++){ A[10-i] = buf_A[(a_length-1)-i] - '0'; } for(int i = 0;i < b_length; i++){ B[10-i] = buf_B[(b_length-1)-i] - '0'; } for(int digit = 10; digit >= 1; digit--){ if(A[digit] >= B[digit]){ C[digit] = A[digit] - B[digit]; }else{ C[digit] = 10 + A[digit] - B[digit]; tmp_digit = digit-1; while(true){ if(A[tmp_digit] != B[tmp_digit]){ S.push(POW[10-tmp_digit]); if(A[tmp_digit] > B[tmp_digit]){ A[tmp_digit]--; break; }else{ if(A[tmp_digit] != 0){ A[tmp_digit]--; break; }else{ A[tmp_digit] = 9; tmp_digit--; } } }else{ //A[tmp_digit] = B[tmp_digit] if(A[tmp_digit] != 0){ A[tmp_digit]--; break; }else{ A[tmp_digit] = 9; tmp_digit--; } } } } } ans = 0; for(int i = 1; i <= 10; i++){ ans += POW[10-i]*C[i]; } while(S.empty() == false && K > 0){ ans += S.top(); K--; S.pop(); } printf("%d\n",ans); return 0; }
### Prompt Please create a solution in Cpp to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <stdio.h> #include <cmath> #include <algorithm> #include <cfloat> #include <stack> #include <queue> #include <vector> typedef long long int ll; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000001 using namespace std; int main(){ int K,A[11],B[11],C[11],ans,tmp_digit,POW[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000}; char buf_A[11],buf_B[11]; stack<int> S; for(int i = 0; i <= 10; i++){ A[i] = 0; B[i] = 0; } scanf("%s %s %d",buf_A,buf_B,&K); int a_length,b_length; for(a_length = 0; buf_A[a_length] != '\0'; a_length++); for(b_length = 0; buf_B[b_length] != '\0'; b_length++); for(int i = 0;i < a_length; i++){ A[10-i] = buf_A[(a_length-1)-i] - '0'; } for(int i = 0;i < b_length; i++){ B[10-i] = buf_B[(b_length-1)-i] - '0'; } for(int digit = 10; digit >= 1; digit--){ if(A[digit] >= B[digit]){ C[digit] = A[digit] - B[digit]; }else{ C[digit] = 10 + A[digit] - B[digit]; tmp_digit = digit-1; while(true){ if(A[tmp_digit] != B[tmp_digit]){ S.push(POW[10-tmp_digit]); if(A[tmp_digit] > B[tmp_digit]){ A[tmp_digit]--; break; }else{ if(A[tmp_digit] != 0){ A[tmp_digit]--; break; }else{ A[tmp_digit] = 9; tmp_digit--; } } }else{ //A[tmp_digit] = B[tmp_digit] if(A[tmp_digit] != 0){ A[tmp_digit]--; break; }else{ A[tmp_digit] = 9; tmp_digit--; } } } } } ans = 0; for(int i = 1; i <= 10; i++){ ans += POW[10-i]*C[i]; } while(S.empty() == false && K > 0){ ans += S.top(); K--; S.pop(); } printf("%d\n",ans); return 0; } ```
#include<bits/stdc++.h> #define LL long long #define REP(i,n) for(int i=0;i<(n);++i) #define lp(i,n) for(int i=0;i<(n);i++) #define REPA(i,n) for(int i=1;i<(n);++i) #define PII pair<int,int> #define PLI pair<long long, int> #define PLL pair<long long, long long> #define MOD ((int)1e9 + 7) #define INF ((int)2e9) #define INFLL ((LL)1e18) #define ALL(x) (x).begin(),(x).end() #define CTOI(x) (x - 'A') #define ctoi(x) (x - 'a') #define BIT(x) (1 << (x)) using namespace std; int a,b,k,si,ans=-1; void solve(int it,int bo,int kcnt,int an){ if(it==si){ ans=max(ans,an); return; } int nowa=a/pow(10,it); nowa%=10; int nowb=b/pow(10,it); nowb%=10; if(nowa-bo>=nowb){ solve(it+1,0,kcnt,an+(nowa-bo-nowb)*pow(10,it)); } else{ if(kcnt!=k){ solve(it+1,0,kcnt+1,an+(nowa-bo+10-nowb)*pow(10,it)); } solve(it+1,1,kcnt,an+(nowa-bo+10-nowb)*pow(10,it)); } return; } int main(){ cin>>a>>b>>k; string s=to_string(a); si=s.size(); solve(0,0,0,0); cout<<ans<<endl; return 0; }
### Prompt Generate a cpp solution to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<bits/stdc++.h> #define LL long long #define REP(i,n) for(int i=0;i<(n);++i) #define lp(i,n) for(int i=0;i<(n);i++) #define REPA(i,n) for(int i=1;i<(n);++i) #define PII pair<int,int> #define PLI pair<long long, int> #define PLL pair<long long, long long> #define MOD ((int)1e9 + 7) #define INF ((int)2e9) #define INFLL ((LL)1e18) #define ALL(x) (x).begin(),(x).end() #define CTOI(x) (x - 'A') #define ctoi(x) (x - 'a') #define BIT(x) (1 << (x)) using namespace std; int a,b,k,si,ans=-1; void solve(int it,int bo,int kcnt,int an){ if(it==si){ ans=max(ans,an); return; } int nowa=a/pow(10,it); nowa%=10; int nowb=b/pow(10,it); nowb%=10; if(nowa-bo>=nowb){ solve(it+1,0,kcnt,an+(nowa-bo-nowb)*pow(10,it)); } else{ if(kcnt!=k){ solve(it+1,0,kcnt+1,an+(nowa-bo+10-nowb)*pow(10,it)); } solve(it+1,1,kcnt,an+(nowa-bo+10-nowb)*pow(10,it)); } return; } int main(){ cin>>a>>b>>k; string s=to_string(a); si=s.size(); solve(0,0,0,0); cout<<ans<<endl; return 0; } ```
#include <iostream> #include <string> #include <algorithm> using namespace std; int dp[11][10][2]; // dp[i][j][k]: i桁まで計算、j回忘れた、直前borrowならk=1 int main() { int a; int b; int k; cin >> a >> b >> k; for(int i = 0; i < 11; i++) { for(int j = 0; j < 10; j++) { dp[i][j][0] = dp[i][j][1] = -1; } } dp[0][0][0] = a; int a2 = a; int b2 = b; int keta = 1; int i; for(i = 0; b2 > 0 || a2 > 0; i++) { // cout << i << endl; int subb = b2 % 10; for(int j = 0; j <= k; j++) { for(int l = 0; l < 2; l++) { if (dp[i][j][l] > 0) { // cout << "dp[]" << i << j <<"," <<l<< ":"<< dp[i][j][l]<<endl; int suba = dp[i][j][l] / keta % 10; int diff = suba - subb - l; if(diff >= 0) { dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][l] - (subb + l) * keta); } else { if (j != k) dp[i+1][j+1][0] = max(dp[i+1][j+1][0], dp[i][j][l] + (10 - subb - l) * keta); dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][l] + (10 - subb - l) * keta); } } } } a2 /= 10; b2 /= 10; keta *= 10; } int maxn = 0; for(int j = 0; j <= k; j++) { maxn = max(maxn, dp[i][j][0]); } cout << maxn << endl; return 0; }
### Prompt Construct a CPP code solution to the problem outlined: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <string> #include <algorithm> using namespace std; int dp[11][10][2]; // dp[i][j][k]: i桁まで計算、j回忘れた、直前borrowならk=1 int main() { int a; int b; int k; cin >> a >> b >> k; for(int i = 0; i < 11; i++) { for(int j = 0; j < 10; j++) { dp[i][j][0] = dp[i][j][1] = -1; } } dp[0][0][0] = a; int a2 = a; int b2 = b; int keta = 1; int i; for(i = 0; b2 > 0 || a2 > 0; i++) { // cout << i << endl; int subb = b2 % 10; for(int j = 0; j <= k; j++) { for(int l = 0; l < 2; l++) { if (dp[i][j][l] > 0) { // cout << "dp[]" << i << j <<"," <<l<< ":"<< dp[i][j][l]<<endl; int suba = dp[i][j][l] / keta % 10; int diff = suba - subb - l; if(diff >= 0) { dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][l] - (subb + l) * keta); } else { if (j != k) dp[i+1][j+1][0] = max(dp[i+1][j+1][0], dp[i][j][l] + (10 - subb - l) * keta); dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][l] + (10 - subb - l) * keta); } } } } a2 /= 10; b2 /= 10; keta *= 10; } int maxn = 0; for(int j = 0; j <= k; j++) { maxn = max(maxn, dp[i][j][0]); } cout << maxn << endl; return 0; } ```
#include <iostream> #include <sstream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> using namespace std; #define FOR(i,k,n) for(int i=(k); i<(int)n; ++i) #define REP(i,n) FOR(i,0,n) #define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; } typedef long long ll; const int INF = 100000000; const double EPS = 1e-8; const int MOD = 1000000007; int rec(int A,int B,int K,int borrow,int C,int ten){ if(A == 0) return C; int a = A%10, b = B % 10; if(a-borrow>=b){ return rec(A/10, B/10, K, 0, C+ten*(a-borrow-b), ten*10); }else{ int res = rec(A/10, B/10, K, 1, C+ten*(a-borrow+10-b), ten*10); if(K > 0)res = max(res, rec(A/10, B/10, K-1, 0, C+ten*(a-borrow+10-b), ten*10)); return res; } } int main(){ int A,B,K; cin>>A>>B>>K; cout<<rec(A,B,K,0,0,1)<<endl; return 0; }
### Prompt Create a solution in CPP for the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <sstream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> using namespace std; #define FOR(i,k,n) for(int i=(k); i<(int)n; ++i) #define REP(i,n) FOR(i,0,n) #define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; } typedef long long ll; const int INF = 100000000; const double EPS = 1e-8; const int MOD = 1000000007; int rec(int A,int B,int K,int borrow,int C,int ten){ if(A == 0) return C; int a = A%10, b = B % 10; if(a-borrow>=b){ return rec(A/10, B/10, K, 0, C+ten*(a-borrow-b), ten*10); }else{ int res = rec(A/10, B/10, K, 1, C+ten*(a-borrow+10-b), ten*10); if(K > 0)res = max(res, rec(A/10, B/10, K-1, 0, C+ten*(a-borrow+10-b), ten*10)); return res; } } int main(){ int A,B,K; cin>>A>>B>>K; cout<<rec(A,B,K,0,0,1)<<endl; return 0; } ```
#include <set> #include <cstring> #include <cstdio> #include <algorithm> #define REP(i,n) for(int i=0; i<(int)(n); i++) #define MEQ(a,b) a = max((a), (b)) inline int getInt(){ int s; scanf("%d", &s); return s; } using namespace std; int memo[10][10][2]; int a[20]; int b[20]; int p[10]; int main(){ int aa = getInt(); int bb = getInt(); int kk = getInt(); REP(i,10){ a[i] = aa % 10; b[i] = bb % 10; aa /= 10; bb /= 10; } p[0] = 1; REP(i,9) p[i + 1] = p[i] * 10; int ans = 0; memset(memo, -1, sizeof(memo)); memo[0][0][0] = 0; REP(i,9) REP(k,kk + 1) REP(j,2) if(memo[i][k][j] >= 0){ int c = a[i] - j - b[i]; if(c < 0){ c += 10; MEQ(memo[i + 1][k + 1][0], memo[i][k][j] + p[i] * c); MEQ(memo[i + 1][k ][1], memo[i][k][j] + p[i] * c); }else{ MEQ(memo[i + 1][k ][0], memo[i][k][j] + p[i] * c); } // printf("%d %d %d: %d\n", i, k, j, memo[i][k][j] + p[i] * c); } REP(k,kk + 1) ans = max(ans, memo[9][k][0]); printf("%d\n", ans); return 0; }
### Prompt Create a solution in Cpp for the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <set> #include <cstring> #include <cstdio> #include <algorithm> #define REP(i,n) for(int i=0; i<(int)(n); i++) #define MEQ(a,b) a = max((a), (b)) inline int getInt(){ int s; scanf("%d", &s); return s; } using namespace std; int memo[10][10][2]; int a[20]; int b[20]; int p[10]; int main(){ int aa = getInt(); int bb = getInt(); int kk = getInt(); REP(i,10){ a[i] = aa % 10; b[i] = bb % 10; aa /= 10; bb /= 10; } p[0] = 1; REP(i,9) p[i + 1] = p[i] * 10; int ans = 0; memset(memo, -1, sizeof(memo)); memo[0][0][0] = 0; REP(i,9) REP(k,kk + 1) REP(j,2) if(memo[i][k][j] >= 0){ int c = a[i] - j - b[i]; if(c < 0){ c += 10; MEQ(memo[i + 1][k + 1][0], memo[i][k][j] + p[i] * c); MEQ(memo[i + 1][k ][1], memo[i][k][j] + p[i] * c); }else{ MEQ(memo[i + 1][k ][0], memo[i][k][j] + p[i] * c); } // printf("%d %d %d: %d\n", i, k, j, memo[i][k][j] + p[i] * c); } REP(k,kk + 1) ans = max(ans, memo[9][k][0]); printf("%d\n", ans); return 0; } ```
#include<bits/stdc++.h> using namespace std; string a,b; int k,n,ans; int num[10]; void dfs(int x,int borrow,int cntk){ if(x==n){ if(cntk<=k){ int t=0; for(int i=n-1;i>=0;i--)t=t*10+num[i]; ans=max(ans,t); } }else{ int A=a[x]-'0',B=b[x]-'0'; if(A-borrow>=B){ num[x]=A-borrow-B; dfs(x+1,0,cntk); }else{ num[x]=A-borrow+10-B; dfs(x+1,0,cntk+1); dfs(x+1,1,cntk); } } } int main(){ cin>>a>>b>>k; n=max(a.size(),b.size()); for(int i=a.size();i<n;i++)a='0'+a; for(int i=b.size();i<n;i++)b='0'+b; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); dfs(0,0,0); cout<<ans<<endl; return 0; }
### Prompt Your task is to create a cpp solution to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<bits/stdc++.h> using namespace std; string a,b; int k,n,ans; int num[10]; void dfs(int x,int borrow,int cntk){ if(x==n){ if(cntk<=k){ int t=0; for(int i=n-1;i>=0;i--)t=t*10+num[i]; ans=max(ans,t); } }else{ int A=a[x]-'0',B=b[x]-'0'; if(A-borrow>=B){ num[x]=A-borrow-B; dfs(x+1,0,cntk); }else{ num[x]=A-borrow+10-B; dfs(x+1,0,cntk+1); dfs(x+1,1,cntk); } } } int main(){ cin>>a>>b>>k; n=max(a.size(),b.size()); for(int i=a.size();i<n;i++)a='0'+a; for(int i=b.size();i<n;i++)b='0'+b; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); dfs(0,0,0); cout<<ans<<endl; return 0; } ```
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; string a,b;int k; int Max=0; string c; void dfs(int i,int p,int t){ if(i==a.size()){ string q=c;reverse(q.begin(),q.end()); Max=max(Max,stoi(q)); return; } if(a[i]-p>=b[i]){ c+=to_string(a[i]-p-b[i]); dfs(i+1,0,t);c.pop_back(); } else{ c+=to_string(a[i]-p+10-b[i]); dfs(i+1,1,t);c.pop_back(); } if(t){ if(a[i]>=b[i]){ c+=to_string(a[i]-b[i]); dfs(i+1,0,t-1);c.pop_back(); } else{ c+=to_string(a[i]+10-b[i]); dfs(i+1,1,t-1);c.pop_back(); } } } int main(){ cin>>a>>b>>k; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); while(a.size()>b.size())b+='0'; for(char&c:a)c-='0'; for(char&c:b)c-='0'; dfs(0,0,k); printf("%d\n",Max); }
### Prompt Your challenge is to write a CPP solution to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; string a,b;int k; int Max=0; string c; void dfs(int i,int p,int t){ if(i==a.size()){ string q=c;reverse(q.begin(),q.end()); Max=max(Max,stoi(q)); return; } if(a[i]-p>=b[i]){ c+=to_string(a[i]-p-b[i]); dfs(i+1,0,t);c.pop_back(); } else{ c+=to_string(a[i]-p+10-b[i]); dfs(i+1,1,t);c.pop_back(); } if(t){ if(a[i]>=b[i]){ c+=to_string(a[i]-b[i]); dfs(i+1,0,t-1);c.pop_back(); } else{ c+=to_string(a[i]+10-b[i]); dfs(i+1,1,t-1);c.pop_back(); } } } int main(){ cin>>a>>b>>k; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); while(a.size()>b.size())b+='0'; for(char&c:a)c-='0'; for(char&c:b)c-='0'; dfs(0,0,k); printf("%d\n",Max); } ```
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int a,b,K; cin>>a>>b>>K; vector<int> A,B; int atmp=a,btmp=b,sz=0; while(atmp){ A.push_back(atmp%10); B.push_back(btmp%10); atmp/=10; btmp/=10; sz++; } int dp[15][2][15]; fill_n(**dp,15*2*15,-1); dp[0][0][0]=0; for(int i=0;i<sz;i++){ for(int j=0;j<2;j++){ for(int k=0;k<=K;k++){ if(dp[i][j][k]==-1)continue; if(A[i]-j>=B[i]){ int cost=(A[i]-j-B[i])*pow(10,i); dp[i+1][0][k]=max(dp[i+1][0][k],dp[i][j][k]+cost); }else{ int cost=(A[i]-j+10-B[i])*pow(10,i); dp[i+1][1][k]=max(dp[i+1][1][k],dp[i][j][k]+cost); dp[i+1][0][k+1]=max(dp[i+1][0][k+1],dp[i][j][k]+cost); } } } } int ans=0; for(int i=0;i<2;i++) for(int j=0;j<=K;j++) ans=max(ans,dp[sz][i][j]); cout<<ans<<endl; return 0; }
### Prompt Construct a CPP code solution to the problem outlined: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int a,b,K; cin>>a>>b>>K; vector<int> A,B; int atmp=a,btmp=b,sz=0; while(atmp){ A.push_back(atmp%10); B.push_back(btmp%10); atmp/=10; btmp/=10; sz++; } int dp[15][2][15]; fill_n(**dp,15*2*15,-1); dp[0][0][0]=0; for(int i=0;i<sz;i++){ for(int j=0;j<2;j++){ for(int k=0;k<=K;k++){ if(dp[i][j][k]==-1)continue; if(A[i]-j>=B[i]){ int cost=(A[i]-j-B[i])*pow(10,i); dp[i+1][0][k]=max(dp[i+1][0][k],dp[i][j][k]+cost); }else{ int cost=(A[i]-j+10-B[i])*pow(10,i); dp[i+1][1][k]=max(dp[i+1][1][k],dp[i][j][k]+cost); dp[i+1][0][k+1]=max(dp[i+1][0][k+1],dp[i][j][k]+cost); } } } } int ans=0; for(int i=0;i<2;i++) for(int j=0;j<=K;j++) ans=max(ans,dp[sz][i][j]); cout<<ans<<endl; return 0; } ```
#include <iostream> #include <algorithm> #include <string> using namespace std; string ANS="0000000000"; void cal(string A,string B,int C,int D){ if(A.size()==D+1){ string st=""; for(int i=0;i<A.size();i++)st+=(A[i]-B[i]+'0'); reverse(st.begin(),st.end()); if(ANS<st)ANS=st; } else{ if(A[D]>=B[D]){ cal(A,B,C,D+1); } else{ A[D]+=10; string AA=A; A[D+1]--; cal(A,B,C,D+1); if(C>0){ cal(AA,B,C-1,D+1); } } } } int main(){ string a,b; int c; cin>>a>>b>>c; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); while(a.size()<10)a+="0"; while(a.size()>b.size())b+="0"; cal(a,b,c,0); for(int i=0,j=0;i<ANS.size();i++){ if(j==0&&ANS[i]!='0')j=1; if(j)cout<<ANS[i]; } cout<<endl; return 0; }
### Prompt Create a solution in Cpp for the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <algorithm> #include <string> using namespace std; string ANS="0000000000"; void cal(string A,string B,int C,int D){ if(A.size()==D+1){ string st=""; for(int i=0;i<A.size();i++)st+=(A[i]-B[i]+'0'); reverse(st.begin(),st.end()); if(ANS<st)ANS=st; } else{ if(A[D]>=B[D]){ cal(A,B,C,D+1); } else{ A[D]+=10; string AA=A; A[D+1]--; cal(A,B,C,D+1); if(C>0){ cal(AA,B,C-1,D+1); } } } } int main(){ string a,b; int c; cin>>a>>b>>c; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); while(a.size()<10)a+="0"; while(a.size()>b.size())b+="0"; cal(a,b,c,0); for(int i=0,j=0;i<ANS.size();i++){ if(j==0&&ANS[i]!='0')j=1; if(j)cout<<ANS[i]; } cout<<endl; return 0; } ```
#include <cstdio> #include <iostream> #include <vector> #include <list> #include <cmath> #include <fstream> #include <algorithm> #include <string> #include <queue> #include <set> #include <map> #include <complex> #include <iterator> #include <cstdlib> #include <cstring> #include <sstream> #include <stack> using namespace std; const double EPS=(1e-10); typedef long long ll; typedef pair<int,int> pii; bool EQ(double a,double b){ return abs((a)-(b))<EPS; } void fast_stream(){ std::ios_base::sync_with_stdio(0); } int getLen(int n){ int cnt=0; if(n==0)return 1; while(n){ cnt++; n/=10; } return cnt; } void solve(){ int A,B,K; cin>>A>>B>>K; int n=getLen(A); string as,bs; for(int i=0;i<n;i++){ as+=(A%10)+'0'; A/=10; } reverse(as.begin(),as.end()); for(int i=0;i<n;i++){ bs+=(B%10)+'0'; B/=10; } reverse(bs.begin(),bs.end()); // ツづつアツづーツ繰ツづィツ可コツつーツつオツづ按つ「ツつゥ ll maxnum=0; for(int mask=0;mask<(1<<n);mask++){ int cnt=0; for(int i=0;i<n;i++){ if((mask>>i)&1)cnt++; } if(cnt>K)continue; string c; // ツ可コツ暗環個つゥツづァツ渉氾板づ可計ツ算 int bor=0; for(int i=n-1;i>=0;i--){ if(as[i]-'0'-bor>=bs[i]-'0'){ c+=as[i]-bor-bs[i]+'0'; bor=0; } else{ c+=as[i]-bor-bs[i]+'0'+10; if((mask>>i)&1)bor=0; else bor=1; } } ll num=0; for(int i=c.size()-1;i>=0;i--){ num=num*10+(c[i]-'0'); } maxnum=max(maxnum,num); } cout<<maxnum<<endl; } int main(){ solve(); return 0; }
### Prompt Develop a solution in CPP to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <cstdio> #include <iostream> #include <vector> #include <list> #include <cmath> #include <fstream> #include <algorithm> #include <string> #include <queue> #include <set> #include <map> #include <complex> #include <iterator> #include <cstdlib> #include <cstring> #include <sstream> #include <stack> using namespace std; const double EPS=(1e-10); typedef long long ll; typedef pair<int,int> pii; bool EQ(double a,double b){ return abs((a)-(b))<EPS; } void fast_stream(){ std::ios_base::sync_with_stdio(0); } int getLen(int n){ int cnt=0; if(n==0)return 1; while(n){ cnt++; n/=10; } return cnt; } void solve(){ int A,B,K; cin>>A>>B>>K; int n=getLen(A); string as,bs; for(int i=0;i<n;i++){ as+=(A%10)+'0'; A/=10; } reverse(as.begin(),as.end()); for(int i=0;i<n;i++){ bs+=(B%10)+'0'; B/=10; } reverse(bs.begin(),bs.end()); // ツづつアツづーツ繰ツづィツ可コツつーツつオツづ按つ「ツつゥ ll maxnum=0; for(int mask=0;mask<(1<<n);mask++){ int cnt=0; for(int i=0;i<n;i++){ if((mask>>i)&1)cnt++; } if(cnt>K)continue; string c; // ツ可コツ暗環個つゥツづァツ渉氾板づ可計ツ算 int bor=0; for(int i=n-1;i>=0;i--){ if(as[i]-'0'-bor>=bs[i]-'0'){ c+=as[i]-bor-bs[i]+'0'; bor=0; } else{ c+=as[i]-bor-bs[i]+'0'+10; if((mask>>i)&1)bor=0; else bor=1; } } ll num=0; for(int i=c.size()-1;i>=0;i--){ num=num*10+(c[i]-'0'); } maxnum=max(maxnum,num); } cout<<maxnum<<endl; } int main(){ solve(); return 0; } ```
//Name: A-B Problem //Level: 2 //Category: 動的計画法,DP //Note: /** * dp[n][k][b] = n桁目以降で、あとk回まで繰り下がりを忘れていい時に作れる最大値(ただしn桁目におけるborrowの値はb) * として、メモ化再帰の形で書く。 * * オーダーは O(K log A)。 */ #include <iostream> #include <string> #include <array> #include <algorithm> using namespace std; template <typename T> struct Maybe {/*{{{*/ T val; bool valid; Maybe() : valid(false) {} Maybe(T &t) : val(t), valid(true) {} T& operator =(const T &rv) { val = rv; valid = true; return val; } };/*}}}*/ string A, B; array<array<array<Maybe<int>,2>,10>,10> memo; int solve(int n, int k, int b) { if(n >= A.size()) return 0; if(memo[n][k][b].valid) return memo[n][k][b].val; const int av = A[n] - '0'; const int bv = n < B.size() ? B[n] - '0' : 0; int ans = 0; // consider borrow { int rem = av - b; if(rem >= bv) { ans = solve(n+1, k, 0) * 10 + (rem - bv); } else { ans = solve(n+1, k, 1) * 10 + (rem + 10 - bv); } } // ignore borrow if(b > 0 && k > 0) { if(av >= bv) { ans = max(ans, solve(n+1, k-1, 0) * 10 + (av - bv)); } else { ans = max(ans, solve(n+1, k-1, 1) * 10 + (av + 10 - bv)); } } memo[n][k][b] = ans; return ans; } bool solve() { int K; if(!(cin >> A >> B >> K)) return false; reverse(begin(A), end(A)); reverse(begin(B), end(B)); for(int n = 0; n < 10; ++n) { for(int k = 0; k <= K; ++k) { for(int b = 0 ; b < 2; ++b) { memo[n][k][b].valid = false; } } } cout << solve(0, K, 0) << endl; return true; } int main() { cin.tie(0); ios::sync_with_stdio(0); while(solve()) ; return 0; }
### Prompt In CPP, your task is to solve the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp //Name: A-B Problem //Level: 2 //Category: 動的計画法,DP //Note: /** * dp[n][k][b] = n桁目以降で、あとk回まで繰り下がりを忘れていい時に作れる最大値(ただしn桁目におけるborrowの値はb) * として、メモ化再帰の形で書く。 * * オーダーは O(K log A)。 */ #include <iostream> #include <string> #include <array> #include <algorithm> using namespace std; template <typename T> struct Maybe {/*{{{*/ T val; bool valid; Maybe() : valid(false) {} Maybe(T &t) : val(t), valid(true) {} T& operator =(const T &rv) { val = rv; valid = true; return val; } };/*}}}*/ string A, B; array<array<array<Maybe<int>,2>,10>,10> memo; int solve(int n, int k, int b) { if(n >= A.size()) return 0; if(memo[n][k][b].valid) return memo[n][k][b].val; const int av = A[n] - '0'; const int bv = n < B.size() ? B[n] - '0' : 0; int ans = 0; // consider borrow { int rem = av - b; if(rem >= bv) { ans = solve(n+1, k, 0) * 10 + (rem - bv); } else { ans = solve(n+1, k, 1) * 10 + (rem + 10 - bv); } } // ignore borrow if(b > 0 && k > 0) { if(av >= bv) { ans = max(ans, solve(n+1, k-1, 0) * 10 + (av - bv)); } else { ans = max(ans, solve(n+1, k-1, 1) * 10 + (av + 10 - bv)); } } memo[n][k][b] = ans; return ans; } bool solve() { int K; if(!(cin >> A >> B >> K)) return false; reverse(begin(A), end(A)); reverse(begin(B), end(B)); for(int n = 0; n < 10; ++n) { for(int k = 0; k <= K; ++k) { for(int b = 0 ; b < 2; ++b) { memo[n][k][b].valid = false; } } } cout << solve(0, K, 0) << endl; return true; } int main() { cin.tie(0); ios::sync_with_stdio(0); while(solve()) ; return 0; } ```
#include <iostream> #include <vector> using namespace std; int borrow, a, b, k, ans, A[10], B[10], C[10], as, bs; void solve(int p, int cnt){ if(p == as){ int tmp = 0; for(int i=0, r=1;i<as;i++,r*=10) tmp += C[i] * r; ans = max(ans, tmp); return; } if(A[p] - borrow >= B[p]){ C[p] = A[p] - borrow - B[p]; borrow = 0; solve(p+1, cnt); }else{ C[p] = A[p] - borrow + 10 - B[p]; borrow = 1; solve(p+1, cnt); if(cnt < k){ borrow = 0; solve(p+1, cnt+1); } } C[p] = 0; } int main(){ cin >> a >> b >> k; fill(C, C+10, 0); for(as=0;;as++){ A[as] = a % 10; if(a == 0) break; a /= 10; } for(bs=0;;bs++){ B[bs] = b % 10; if(b == 0) break; b /= 10; } for(int i=bs;i<as;i++) B[i] = 0; ans = borrow = 0; solve(0, 0); cout << ans << endl; }
### Prompt Create a solution in cpp for the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <vector> using namespace std; int borrow, a, b, k, ans, A[10], B[10], C[10], as, bs; void solve(int p, int cnt){ if(p == as){ int tmp = 0; for(int i=0, r=1;i<as;i++,r*=10) tmp += C[i] * r; ans = max(ans, tmp); return; } if(A[p] - borrow >= B[p]){ C[p] = A[p] - borrow - B[p]; borrow = 0; solve(p+1, cnt); }else{ C[p] = A[p] - borrow + 10 - B[p]; borrow = 1; solve(p+1, cnt); if(cnt < k){ borrow = 0; solve(p+1, cnt+1); } } C[p] = 0; } int main(){ cin >> a >> b >> k; fill(C, C+10, 0); for(as=0;;as++){ A[as] = a % 10; if(a == 0) break; a /= 10; } for(bs=0;;bs++){ B[bs] = b % 10; if(b == 0) break; b /= 10; } for(int i=bs;i<as;i++) B[i] = 0; ans = borrow = 0; solve(0, 0); cout << ans << endl; } ```
#include <iostream> #include <algorithm> #include <string> using namespace std; string A, B; int K, N; int ten[11]; bool flag[11]; int rec(int p, int k) { if(p == N) { int res = 0; for(int i = 0, borrow = 0; i < N; ++i) { int a, b; a = A[i]-'0', b = B[i]-'0'; if(a-borrow >= b) { res += ten[i]*(a-borrow-b); borrow = 0; } else { res += ten[i]*(a-borrow+10-b); if(flag[i]) borrow = 0; else borrow = 1; } } return res; } int res; flag[p] = false; res = rec(p+1,k); if(k < K) { flag[p] = true; res = max(res,rec(p+1,k+1)); } return res; } int main() { ten[0] = 1; for(int i = 1; i < 11; ++i) ten[i] = ten[i-1]*10; cin >> A >> B >> K; N = A.size(); reverse(A.begin(), A.end()); reverse(B.begin(), B.end()); while(A.size() != B.size()) B += "0"; int ans = 0; for(int k = 0; k <= K; ++k) ans = max(ans,rec(0,0)); cout << ans << endl; return 0; }
### Prompt Your challenge is to write a CPP solution to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <algorithm> #include <string> using namespace std; string A, B; int K, N; int ten[11]; bool flag[11]; int rec(int p, int k) { if(p == N) { int res = 0; for(int i = 0, borrow = 0; i < N; ++i) { int a, b; a = A[i]-'0', b = B[i]-'0'; if(a-borrow >= b) { res += ten[i]*(a-borrow-b); borrow = 0; } else { res += ten[i]*(a-borrow+10-b); if(flag[i]) borrow = 0; else borrow = 1; } } return res; } int res; flag[p] = false; res = rec(p+1,k); if(k < K) { flag[p] = true; res = max(res,rec(p+1,k+1)); } return res; } int main() { ten[0] = 1; for(int i = 1; i < 11; ++i) ten[i] = ten[i-1]*10; cin >> A >> B >> K; N = A.size(); reverse(A.begin(), A.end()); reverse(B.begin(), B.end()); while(A.size() != B.size()) B += "0"; int ans = 0; for(int k = 0; k <= K; ++k) ans = max(ans,rec(0,0)); cout << ans << endl; return 0; } ```
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <bitset> #define rep(i, n) for(int i = 0; i < (n); i++) #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define all(v) (v).begin(), (v).end() #define rev(s) (s).rbegin(), (s).rend() #define MP make_pair #define X first #define Y second using namespace std; typedef long long ll; typedef pair<int, int> P; const int INF = 1<<29; string A, B; int dfs(int borrow, int K, int i){ if(i == A.size()) return 0; int bi = (borrow>>i)&1; int res = 0; if(K > 0 && bi){ res = dfs(borrow&(~(1<<i)), K-1, i); } int C = 0; if(A[i] - bi >= B[i]){ C = (A[i] - bi - B[i]); }else{ C = (A[i] - bi + 10 - B[i]); borrow |= (1<<i+1); } return max(res, C + 10*dfs(borrow, K, i+1)); } int main(){ int K; cin >> A >> B >> K; reverse(all(A)); reverse(all(B)); while(B.size() < A.size()) B += '0'; cout << dfs(0, K, 0) << endl; return 0; }
### Prompt Your task is to create a cpp solution to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <vector> #include <algorithm> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <bitset> #define rep(i, n) for(int i = 0; i < (n); i++) #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define all(v) (v).begin(), (v).end() #define rev(s) (s).rbegin(), (s).rend() #define MP make_pair #define X first #define Y second using namespace std; typedef long long ll; typedef pair<int, int> P; const int INF = 1<<29; string A, B; int dfs(int borrow, int K, int i){ if(i == A.size()) return 0; int bi = (borrow>>i)&1; int res = 0; if(K > 0 && bi){ res = dfs(borrow&(~(1<<i)), K-1, i); } int C = 0; if(A[i] - bi >= B[i]){ C = (A[i] - bi - B[i]); }else{ C = (A[i] - bi + 10 - B[i]); borrow |= (1<<i+1); } return max(res, C + 10*dfs(borrow, K, i+1)); } int main(){ int K; cin >> A >> B >> K; reverse(all(A)); reverse(all(B)); while(B.size() < A.size()) B += '0'; cout << dfs(0, K, 0) << endl; return 0; } ```
#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #define ll long long using namespace std; int digitAt(int arg, int d){ int ret; ret = arg % (int)pow(10, d+1); ret /= (int)pow(10, d); return ret; } int bitcount(int arg){ int ret=0; while(arg > 0){ if(arg & 1) ret++; arg >>= 1; } return ret; } int main(){ int a,b,k,tmp=0,borrow=0,ta,tb,ret=0; cin >> a >> b >> k; int n = log10(a) + 1; for(int i=0;i<(1 << n);i++){ if(bitcount(i) <= k){ tmp = 0; borrow = 0; for(int j=0;j<n;j++){ ta = digitAt(a,j); tb = digitAt(b,j); if(ta - borrow >= tb){ tmp += (ta - tb - borrow) * pow(10, j); borrow = 0; }else{ tmp += (ta - tb - borrow + 10) * pow(10, j); if((1 << j) & i){ borrow = 0; }else{ borrow = 1; } } } ret = max(ret, tmp); } } cout << ret << endl; }
### Prompt Generate a CPP solution to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <algorithm> #include <cstring> #include <cmath> #define ll long long using namespace std; int digitAt(int arg, int d){ int ret; ret = arg % (int)pow(10, d+1); ret /= (int)pow(10, d); return ret; } int bitcount(int arg){ int ret=0; while(arg > 0){ if(arg & 1) ret++; arg >>= 1; } return ret; } int main(){ int a,b,k,tmp=0,borrow=0,ta,tb,ret=0; cin >> a >> b >> k; int n = log10(a) + 1; for(int i=0;i<(1 << n);i++){ if(bitcount(i) <= k){ tmp = 0; borrow = 0; for(int j=0;j<n;j++){ ta = digitAt(a,j); tb = digitAt(b,j); if(ta - borrow >= tb){ tmp += (ta - tb - borrow) * pow(10, j); borrow = 0; }else{ tmp += (ta - tb - borrow + 10) * pow(10, j); if((1 << j) & i){ borrow = 0; }else{ borrow = 1; } } } ret = max(ret, tmp); } } cout << ret << endl; } ```
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <cfloat> #include <ctime> #include <cassert> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> #include <numeric> #include <list> using namespace std; #ifdef _MSC_VER #define __typeof__ decltype template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; } #endif #define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it) #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define CLEAR(arr, val) memset(arr, val, sizeof(arr)) #define rep(i, n) for (int i = 0; i < n; ++i) template <class T> void max_swap(T& a, const T& b) { a = max(a, b); } template <class T> void min_swap(T& a, const T& b) { a = min(a, b); } typedef long long ll; typedef pair<int, int> pint; const double EPS = 1e-8; const double PI = acos(-1.0); const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { 1, 0, -1, 0 }; bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; } int solve(int A, int B, int K) { int mask[10]; for (int i = 0; i < 10; ++i) mask[i] = K-- > 0 ? 0 : 1; sort(mask, mask + 10); int res = -1; do { int c[10] = { 0 } ; int bor[10] = { 0 }; for (int i = 0, a = A, b = B; i < 10; ++i, a /= 10, b /= 10) { int x = a % 10, y = b % 10; int z = x - y - (bor[i] & mask[i]); if (z < 0) { z += 10; bor[i + 1] = 1; } c[i] = z; } int r = 0; for (int i = 9; i >= 0; --i) r = r * 10 + c[i]; max_swap(res, r); } while (next_permutation(mask, mask + 10)); return res; } int main() { int a, b, k; cin >> a >> b >> k; int res = -1; for (int i = 0; i <= k; ++i) max_swap(res, solve(a, b, i)); cout << res << endl; }
### Prompt Create a solution in cpp for the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <cfloat> #include <ctime> #include <cassert> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> #include <numeric> #include <list> using namespace std; #ifdef _MSC_VER #define __typeof__ decltype template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; } #endif #define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it) #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define CLEAR(arr, val) memset(arr, val, sizeof(arr)) #define rep(i, n) for (int i = 0; i < n; ++i) template <class T> void max_swap(T& a, const T& b) { a = max(a, b); } template <class T> void min_swap(T& a, const T& b) { a = min(a, b); } typedef long long ll; typedef pair<int, int> pint; const double EPS = 1e-8; const double PI = acos(-1.0); const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { 1, 0, -1, 0 }; bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; } int solve(int A, int B, int K) { int mask[10]; for (int i = 0; i < 10; ++i) mask[i] = K-- > 0 ? 0 : 1; sort(mask, mask + 10); int res = -1; do { int c[10] = { 0 } ; int bor[10] = { 0 }; for (int i = 0, a = A, b = B; i < 10; ++i, a /= 10, b /= 10) { int x = a % 10, y = b % 10; int z = x - y - (bor[i] & mask[i]); if (z < 0) { z += 10; bor[i + 1] = 1; } c[i] = z; } int r = 0; for (int i = 9; i >= 0; --i) r = r * 10 + c[i]; max_swap(res, r); } while (next_permutation(mask, mask + 10)); return res; } int main() { int a, b, k; cin >> a >> b >> k; int res = -1; for (int i = 0; i <= k; ++i) max_swap(res, solve(a, b, i)); cout << res << endl; } ```
/* * 2350.cc: A-B Problem */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 10; /* typedef */ /* global variables */ int as[MAX_N], bs[MAX_N], cs[MAX_N + 1], brs[MAX_N + 1], tens[MAX_N + 1]; bool deps[MAX_N + 1]; /* subroutines */ /* main */ int main() { int a, b, k; cin >> a >> b >> k; int n = 0; for (; a; a /= 10) as[n++] = a % 10; //printf("n=%d\n", n); for (int i = 0; i < n; i++) { bs[i] = b % 10; b /= 10; } brs[0] = 0; tens[0] = 1; for (int i = 0; i < n; i++) { if (as[i] - brs[i] >= bs[i]) { cs[i] = as[i] - brs[i] - bs[i]; brs[i + 1] = 0; } else { cs[i] = as[i] - brs[i] + 10 - bs[i]; brs[i + 1] = 1; deps[i + 1] = (as[i] == bs[i]); } tens[i + 1] = tens[i] * 10; } //for (int i = n - 1; i >= 0; i--) printf("%d ", brs[i]); putchar('\n'); //for (int i = n - 1; i >= 0; i--) printf("%d ", deps[i]); putchar('\n'); //for (int i = n - 1; i >= 0; i--) printf("%d ", cs[i]); putchar('\n'); for (int i = n - 1; i >= 0 && k > 0; i--) if (brs[i] && ! deps[i + 1]) { //printf("i=%d: %d->%d\n", i, cs[i], cs[i] + 1); cs[i]++, k--; } int ans = 0; for (int i = n - 1; i >= 0; i--) ans = ans * 10 + cs[i]; printf("%d\n", ans); return 0; }
### Prompt Create a solution in Cpp for the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp /* * 2350.cc: A-B Problem */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 10; /* typedef */ /* global variables */ int as[MAX_N], bs[MAX_N], cs[MAX_N + 1], brs[MAX_N + 1], tens[MAX_N + 1]; bool deps[MAX_N + 1]; /* subroutines */ /* main */ int main() { int a, b, k; cin >> a >> b >> k; int n = 0; for (; a; a /= 10) as[n++] = a % 10; //printf("n=%d\n", n); for (int i = 0; i < n; i++) { bs[i] = b % 10; b /= 10; } brs[0] = 0; tens[0] = 1; for (int i = 0; i < n; i++) { if (as[i] - brs[i] >= bs[i]) { cs[i] = as[i] - brs[i] - bs[i]; brs[i + 1] = 0; } else { cs[i] = as[i] - brs[i] + 10 - bs[i]; brs[i + 1] = 1; deps[i + 1] = (as[i] == bs[i]); } tens[i + 1] = tens[i] * 10; } //for (int i = n - 1; i >= 0; i--) printf("%d ", brs[i]); putchar('\n'); //for (int i = n - 1; i >= 0; i--) printf("%d ", deps[i]); putchar('\n'); //for (int i = n - 1; i >= 0; i--) printf("%d ", cs[i]); putchar('\n'); for (int i = n - 1; i >= 0 && k > 0; i--) if (brs[i] && ! deps[i + 1]) { //printf("i=%d: %d->%d\n", i, cs[i], cs[i] + 1); cs[i]++, k--; } int ans = 0; for (int i = n - 1; i >= 0; i--) ans = ans * 10 + cs[i]; printf("%d\n", ans); return 0; } ```
#include<algorithm> #include<cstdio> #include<cstring> using namespace std; char a[11],b[11]; int c[10][2][10],lna,lnb; int fn(int p,int q,int r){ if(p==lna) return 0; if(c[p][q][r]) return c[p][q][r]; if(a[lna-p-1]-q<(lnb-p-1<0?'0':b[lnb-p-1])) return c[p][q][r]=a[lna-p-1]-'0'-q-(lnb-p-1<0?0:b[lnb-p-1]-'0')+10+max(fn(p+1,1,r),r?fn(p+1,0,r-1):0)*10; else return c[p][q][r]=a[lna-p-1]-'0'-q-(lnb-p-1<0?0:b[lnb-p-1]-'0')+fn(p+1,0,r)*10; } int main(){ int n; scanf("%s%s%d",a,b,&n); lna=strlen(a); lnb=strlen(b); printf("%d\n",fn(0,0,n)); return 0; }
### Prompt Construct a cpp code solution to the problem outlined: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<algorithm> #include<cstdio> #include<cstring> using namespace std; char a[11],b[11]; int c[10][2][10],lna,lnb; int fn(int p,int q,int r){ if(p==lna) return 0; if(c[p][q][r]) return c[p][q][r]; if(a[lna-p-1]-q<(lnb-p-1<0?'0':b[lnb-p-1])) return c[p][q][r]=a[lna-p-1]-'0'-q-(lnb-p-1<0?0:b[lnb-p-1]-'0')+10+max(fn(p+1,1,r),r?fn(p+1,0,r-1):0)*10; else return c[p][q][r]=a[lna-p-1]-'0'-q-(lnb-p-1<0?0:b[lnb-p-1]-'0')+fn(p+1,0,r)*10; } int main(){ int n; scanf("%s%s%d",a,b,&n); lna=strlen(a); lnb=strlen(b); printf("%d\n",fn(0,0,n)); return 0; } ```
#include<iostream> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) int solve(string a, string b, int k) { if (a.size() == 0u) return 0; if (a[a.size() - 1] >= b[b.size() - 1]) { return solve(a.substr(0, a.size() - 1), b.substr(0, b.size() - 1), k) * 10 + a[a.size() - 1] - b[b.size() - 1]; } int res = -1000000000; if (k > 0) { res = solve(a.substr(0, a.size() - 1), b.substr(0, b.size() - 1), k - 1) * 10 + a[a.size() - 1] - b[b.size() - 1] + 10; } for (int i = a.size() - 2; i >= 0; --i) { if (a[i] != '0') { --a[i]; break; } a[i] = '9'; if (k > 0) res = max(res, solve(a.substr(0, a.size() - 1), b.substr(0, b.size() - 1), k - 1) * 10 + a[a.size() - 1] - b[b.size() - 1] + 10); } return max(res, solve(a.substr(0, a.size() - 1), b.substr(0, b.size() - 1), k) * 10 + a[a.size() - 1] - b[b.size() - 1] + 10); } int main() { string a, b; int k; cin >> a >> b >> k; while (b.size() < a.size()) b = "0" + b; cout << solve(a, b, k) << endl; return 0; }
### Prompt Develop a solution in CPP to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<iostream> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) int solve(string a, string b, int k) { if (a.size() == 0u) return 0; if (a[a.size() - 1] >= b[b.size() - 1]) { return solve(a.substr(0, a.size() - 1), b.substr(0, b.size() - 1), k) * 10 + a[a.size() - 1] - b[b.size() - 1]; } int res = -1000000000; if (k > 0) { res = solve(a.substr(0, a.size() - 1), b.substr(0, b.size() - 1), k - 1) * 10 + a[a.size() - 1] - b[b.size() - 1] + 10; } for (int i = a.size() - 2; i >= 0; --i) { if (a[i] != '0') { --a[i]; break; } a[i] = '9'; if (k > 0) res = max(res, solve(a.substr(0, a.size() - 1), b.substr(0, b.size() - 1), k - 1) * 10 + a[a.size() - 1] - b[b.size() - 1] + 10); } return max(res, solve(a.substr(0, a.size() - 1), b.substr(0, b.size() - 1), k) * 10 + a[a.size() - 1] - b[b.size() - 1] + 10); } int main() { string a, b; int k; cin >> a >> b >> k; while (b.size() < a.size()) b = "0" + b; cout << solve(a, b, k) << endl; return 0; } ```
#include <iostream> #include <vector> #include <cstring> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; typedef vector<int> vi; int va[12]; int vb[12]; int dp[12][12][2]; int solve(int i, int k, int borrow){ if(i == 12) return 0; int& d = dp[i][k][borrow]; if(d != -1) return d; int x = va[i] - borrow - vb[i]; if(x >= 0) return 10 * solve(i+1, k, 0) + x; int ans = 10 * solve(i+1, k, 1) + x + 10; if(k != 0) ans = max(ans, 10 * solve(i+1, k-1, 0) + x + 10); return d = ans; } int main(){ int a,b,k; cin >> a >> b >> k; rep(i, 12){ va[i] = a % 10; a /= 10; vb[i] = b % 10; b /= 10; } memset(dp, -1, sizeof(dp)); cout << solve(0, k, 0) << endl; return 0; }
### Prompt Develop a solution in cpp to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <vector> #include <cstring> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; typedef vector<int> vi; int va[12]; int vb[12]; int dp[12][12][2]; int solve(int i, int k, int borrow){ if(i == 12) return 0; int& d = dp[i][k][borrow]; if(d != -1) return d; int x = va[i] - borrow - vb[i]; if(x >= 0) return 10 * solve(i+1, k, 0) + x; int ans = 10 * solve(i+1, k, 1) + x + 10; if(k != 0) ans = max(ans, 10 * solve(i+1, k-1, 0) + x + 10); return d = ans; } int main(){ int a,b,k; cin >> a >> b >> k; rep(i, 12){ va[i] = a % 10; a /= 10; vb[i] = b % 10; b /= 10; } memset(dp, -1, sizeof(dp)); cout << solve(0, k, 0) << endl; return 0; } ```
#include<iostream> using namespace std; int mx; int nm[11],ans; void dfs(int a,int b,int brw,int k,int x){ int ai,bi; if(a==0){ int pnt=0; for(int i=x-1;i>=0;i--) pnt=pnt*10+nm[i]; ans=max(ans,pnt); return; } ai=a%10,bi=b%10; a/=10,b/=10; if(brw==0){ if(ai-brw>=bi) nm[x]=ai-brw-bi,brw=0; else nm[x]=ai-brw-bi+10,brw=1; dfs(a,b,brw,k,x+1); }else{ if(k>0){ brw=0; if(ai-brw>=bi)nm[x]=ai-brw-bi,brw=0; else nm[x]=ai-brw-bi+10,brw=1; dfs(a,b,brw,k-1,x+1); } brw=1; if(ai-brw>=bi) nm[x]=ai-brw-bi,brw=0; else nm[x]=ai-brw-bi+10,brw=1; dfs(a,b,brw,k,x+1); } } int main(){ int k,brw=0,a,b; cin>>a>>b>>k; dfs(a,b,brw,k,0); cout<<ans<<endl; return 0; }
### Prompt In Cpp, your task is to solve the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<iostream> using namespace std; int mx; int nm[11],ans; void dfs(int a,int b,int brw,int k,int x){ int ai,bi; if(a==0){ int pnt=0; for(int i=x-1;i>=0;i--) pnt=pnt*10+nm[i]; ans=max(ans,pnt); return; } ai=a%10,bi=b%10; a/=10,b/=10; if(brw==0){ if(ai-brw>=bi) nm[x]=ai-brw-bi,brw=0; else nm[x]=ai-brw-bi+10,brw=1; dfs(a,b,brw,k,x+1); }else{ if(k>0){ brw=0; if(ai-brw>=bi)nm[x]=ai-brw-bi,brw=0; else nm[x]=ai-brw-bi+10,brw=1; dfs(a,b,brw,k-1,x+1); } brw=1; if(ai-brw>=bi) nm[x]=ai-brw-bi,brw=0; else nm[x]=ai-brw-bi+10,brw=1; dfs(a,b,brw,k,x+1); } } int main(){ int k,brw=0,a,b; cin>>a>>b>>k; dfs(a,b,brw,k,0); cout<<ans<<endl; return 0; } ```
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; int K; int solve(const vector<int>& A, const vector<int>& B, vector<int> C, int i, int k, int borrow) { int ret = 0; if (i >= C.size()) { reverse(C.begin(), C.end()); for (i = 0; i < 10; ++i) { ret *= 10; ret += C[i]; } return ret; } if (A[i] - borrow >= B[i]) { C[i] = A[i] - borrow - B[i]; ret = max(ret, solve(A, B, C, i+1, k, 0)); } else { C[i] = A[i] - borrow + 10 - B[i]; if (k < K) ret = max(ret, solve(A, B, C, i+1, k+1, 0)); ret = max(ret, solve(A, B, C, i+1, k, 1)); } return ret; } int main() { string A, B; while (cin >> A >> B >> K) { vector<int> AA(10, 0), BB(10, 0), C(10, 0); for (int i = 0; i < A.size(); ++i) AA[i] = A[A.size()-i-1] - '0'; for (int i = 0; i < B.size(); ++i) BB[i] = B[B.size()-i-1] - '0'; cout << solve(AA, BB, C, 0, 0, 0) << endl; } return 0; }
### Prompt Please provide a cpp coded solution to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; int K; int solve(const vector<int>& A, const vector<int>& B, vector<int> C, int i, int k, int borrow) { int ret = 0; if (i >= C.size()) { reverse(C.begin(), C.end()); for (i = 0; i < 10; ++i) { ret *= 10; ret += C[i]; } return ret; } if (A[i] - borrow >= B[i]) { C[i] = A[i] - borrow - B[i]; ret = max(ret, solve(A, B, C, i+1, k, 0)); } else { C[i] = A[i] - borrow + 10 - B[i]; if (k < K) ret = max(ret, solve(A, B, C, i+1, k+1, 0)); ret = max(ret, solve(A, B, C, i+1, k, 1)); } return ret; } int main() { string A, B; while (cin >> A >> B >> K) { vector<int> AA(10, 0), BB(10, 0), C(10, 0); for (int i = 0; i < A.size(); ++i) AA[i] = A[A.size()-i-1] - '0'; for (int i = 0; i < B.size(); ++i) BB[i] = B[B.size()-i-1] - '0'; cout << solve(AA, BB, C, 0, 0, 0) << endl; } return 0; } ```
#include <cstdio> #include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloat> using namespace std; int solve(int a, int b, int k, int borrow) { if(a == 0 && b == 0) return 0; if(a % 10 - borrow >= b % 10) return solve(a/10, b/10, k, 0) * 10 + (a%10) - borrow - (b%10); int ret = solve(a/10, b/10, k, 1) * 10 + (a%10) - borrow + 10 - (b%10); if(k > 0) ret = max(ret, solve(a/10, b/10, k-1, 0) * 10 + (a%10) - borrow + 10 - (b%10)); return ret; } int main() { int a, b, k; cin >> a >> b >> k; cout << solve(a, b, k, 0) << endl; return 0; }
### Prompt Please provide a Cpp coded solution to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <cstdio> #include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloat> using namespace std; int solve(int a, int b, int k, int borrow) { if(a == 0 && b == 0) return 0; if(a % 10 - borrow >= b % 10) return solve(a/10, b/10, k, 0) * 10 + (a%10) - borrow - (b%10); int ret = solve(a/10, b/10, k, 1) * 10 + (a%10) - borrow + 10 - (b%10); if(k > 0) ret = max(ret, solve(a/10, b/10, k-1, 0) * 10 + (a%10) - borrow + 10 - (b%10)); return ret; } int main() { int a, b, k; cin >> a >> b >> k; cout << solve(a, b, k, 0) << endl; return 0; } ```
#include<iostream> #include<cstring> #include<cstdio> using namespace std; #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) /* 計算量はたかだか2^9 */ int ans; void solve(int now,int val,int base,int *a,int *b,int borrow,int k){ if (k < 0)return; if (now == -1){ ans = max(ans,val); return; } if (a[now]-borrow >= b[now]){ solve(now-1,val + base * (a[now]-borrow-b[now] ),base*10,a,b,0,k); }else { solve(now-1,val + base * (a[now]-borrow+10-b[now]),base*10,a,b,1,k); solve(now-1,val + base * (a[now]-borrow+10-b[now]),base*10,a,b,0,k-1); } } int main(){ int a,b,k; char buf[20]; int aa[12],ba[12]; while(cin>>a>>b>>k){ sprintf(buf,"%d",a); int len = strlen(buf); rep(i,len)aa[i] = buf[i]-'0'; sprintf(buf,"%d",b); int lenb = strlen(buf); rep(i,lenb)ba[i+len-lenb] = buf[i] - '0'; rep(i,len-lenb)ba[i] = 0; ans = 0; solve(len-1,0,1,aa,ba,0,k); cout << ans << endl; } return 0; }
### Prompt Please formulate a Cpp solution to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<iostream> #include<cstring> #include<cstdio> using namespace std; #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) /* 計算量はたかだか2^9 */ int ans; void solve(int now,int val,int base,int *a,int *b,int borrow,int k){ if (k < 0)return; if (now == -1){ ans = max(ans,val); return; } if (a[now]-borrow >= b[now]){ solve(now-1,val + base * (a[now]-borrow-b[now] ),base*10,a,b,0,k); }else { solve(now-1,val + base * (a[now]-borrow+10-b[now]),base*10,a,b,1,k); solve(now-1,val + base * (a[now]-borrow+10-b[now]),base*10,a,b,0,k-1); } } int main(){ int a,b,k; char buf[20]; int aa[12],ba[12]; while(cin>>a>>b>>k){ sprintf(buf,"%d",a); int len = strlen(buf); rep(i,len)aa[i] = buf[i]-'0'; sprintf(buf,"%d",b); int lenb = strlen(buf); rep(i,lenb)ba[i+len-lenb] = buf[i] - '0'; rep(i,len-lenb)ba[i] = 0; ans = 0; solve(len-1,0,1,aa,ba,0,k); cout << ans << endl; } return 0; } ```
#include <iostream> #include <string> #include <algorithm> using namespace std; int main(){ int a, b, k; cin >> a >> b >> k; int answer = a - b; for(int i = 0; i < (1 << 10); ++i){ int p = a, q = b, borrow = 0, result = 0; if(__builtin_popcount(i) > k){ continue; } for(int j = 0, d = 1; p || q; ++j, d *= 10, p /= 10, q /= 10){ int x = p % 10, y = q % 10; if(x - borrow >= y){ result += (x - borrow - y) * d; borrow = 0; }else if(i & (1 << j)){ result += (x - borrow - y + 10) * d; borrow = 0; }else{ result += (x - borrow - y + 10) * d; borrow = 1; } } if(borrow == 0){ answer = max(answer, result); } } cout << answer << endl; return 0; }
### Prompt Please create a solution in cpp to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <string> #include <algorithm> using namespace std; int main(){ int a, b, k; cin >> a >> b >> k; int answer = a - b; for(int i = 0; i < (1 << 10); ++i){ int p = a, q = b, borrow = 0, result = 0; if(__builtin_popcount(i) > k){ continue; } for(int j = 0, d = 1; p || q; ++j, d *= 10, p /= 10, q /= 10){ int x = p % 10, y = q % 10; if(x - borrow >= y){ result += (x - borrow - y) * d; borrow = 0; }else if(i & (1 << j)){ result += (x - borrow - y + 10) * d; borrow = 0; }else{ result += (x - borrow - y + 10) * d; borrow = 1; } } if(borrow == 0){ answer = max(answer, result); } } cout << answer << endl; return 0; } ```
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <math.h> #include <assert.h> #include <vector> #include <queue> #include <string> #include <map> #include <set> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; static const double EPS = 1e-9; static const double PI = acos(-1.0); #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, s, n) for (int i = (s); i < (int)(n); i++) #define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++) #define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++) #define MEMSET(v, h) memset((v), h, sizeof(v)) int len; char A[40]; char B[40]; ll calc(string A, string B, int borrow, int depth, int rest); ll NextState(string A, string B, int borrow, int depth, int rest) { int nborrow = 0; int c = A[depth] - B[depth] + '0' - borrow; if (c < '0') { c += 10; nborrow = 1; } A[depth] = c; return calc(A, B, nborrow, depth - 1, rest); } ll calc(string A, string B, int borrow, int depth, int rest) { if (depth == -1) { return atoi(A.c_str()); } ll ret = 0; if (rest != 0 && borrow) { ret = max(ret, NextState(A, B, 0, depth, rest - 1)); } ret = max(ret, NextState(A, B, borrow, depth, rest)); return ret; } int main() { MEMSET(A, '0'); MEMSET(B, '0'); int k; while (scanf("%s %s %d", A + 20, B + 20, &k) > 0) { len = strlen(A + 20); printf("%lld\n", calc(A + 20, B + 20 - (len - strlen(B + 20)), 0, len - 1, k)); MEMSET(A, '0'); MEMSET(B, '0'); } }
### Prompt Create a solution in cpp for the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <math.h> #include <assert.h> #include <vector> #include <queue> #include <string> #include <map> #include <set> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; static const double EPS = 1e-9; static const double PI = acos(-1.0); #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, s, n) for (int i = (s); i < (int)(n); i++) #define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++) #define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++) #define MEMSET(v, h) memset((v), h, sizeof(v)) int len; char A[40]; char B[40]; ll calc(string A, string B, int borrow, int depth, int rest); ll NextState(string A, string B, int borrow, int depth, int rest) { int nborrow = 0; int c = A[depth] - B[depth] + '0' - borrow; if (c < '0') { c += 10; nborrow = 1; } A[depth] = c; return calc(A, B, nborrow, depth - 1, rest); } ll calc(string A, string B, int borrow, int depth, int rest) { if (depth == -1) { return atoi(A.c_str()); } ll ret = 0; if (rest != 0 && borrow) { ret = max(ret, NextState(A, B, 0, depth, rest - 1)); } ret = max(ret, NextState(A, B, borrow, depth, rest)); return ret; } int main() { MEMSET(A, '0'); MEMSET(B, '0'); int k; while (scanf("%s %s %d", A + 20, B + 20, &k) > 0) { len = strlen(A + 20); printf("%lld\n", calc(A + 20, B + 20 - (len - strlen(B + 20)), 0, len - 1, k)); MEMSET(A, '0'); MEMSET(B, '0'); } } ```
#define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <cmath> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> #include <bitset> using namespace std; typedef long long ll; typedef pair<int,int> P; void dfs(const string& A,const string& B,string C,int pos,int borrow,int K,string& res){ if(K<0) return; if(pos == A.size()){ reverse(C.begin(),C.end()); res = max(res,C); //cout << res << endl; return; } if((A[pos]-'0') - borrow >= (B[pos]-'0')){ C[pos] = ((A[pos]-'0') - borrow - (B[pos]-'0') + '0'); if(C[pos] < '0' || C[pos] > '9') return; dfs(A,B,C,pos+1,0,K,res); } else if((A[pos]-'0') - borrow < (B[pos]-'0')){ C[pos] = ((A[pos]-'0') - borrow + 10 - (B[pos]-'0') + '0'); if(C[pos] < '0' || C[pos] > '9') return; dfs(A,B,C,pos+1,1,K,res); dfs(A,B,C,pos+1,0,K-1,res); } } int main(){ char A[16],B[16]; int K; while(~scanf("%s %s %d",A,B,&K)){ string strA=A,strB=B; reverse(strA.begin(),strA.end()); reverse(strB.begin(),strB.end()); strA.size() > strB.size() ? strB.append(strA.size()-strB.size(),'0') : strA.append(strB.size()-strA.size(),'0'); string strC; string res; strC.resize(max(strA.size(),strB.size())); dfs(strA,strB,strC,0,0,K,res); bool isok = false; for(int i=0;i<res.size();i++){ if(res[i] != '0') isok = true; if(isok) cout << res[i]; } cout << endl; } }
### Prompt Construct a CPP code solution to the problem outlined: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <cmath> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> #include <bitset> using namespace std; typedef long long ll; typedef pair<int,int> P; void dfs(const string& A,const string& B,string C,int pos,int borrow,int K,string& res){ if(K<0) return; if(pos == A.size()){ reverse(C.begin(),C.end()); res = max(res,C); //cout << res << endl; return; } if((A[pos]-'0') - borrow >= (B[pos]-'0')){ C[pos] = ((A[pos]-'0') - borrow - (B[pos]-'0') + '0'); if(C[pos] < '0' || C[pos] > '9') return; dfs(A,B,C,pos+1,0,K,res); } else if((A[pos]-'0') - borrow < (B[pos]-'0')){ C[pos] = ((A[pos]-'0') - borrow + 10 - (B[pos]-'0') + '0'); if(C[pos] < '0' || C[pos] > '9') return; dfs(A,B,C,pos+1,1,K,res); dfs(A,B,C,pos+1,0,K-1,res); } } int main(){ char A[16],B[16]; int K; while(~scanf("%s %s %d",A,B,&K)){ string strA=A,strB=B; reverse(strA.begin(),strA.end()); reverse(strB.begin(),strB.end()); strA.size() > strB.size() ? strB.append(strA.size()-strB.size(),'0') : strA.append(strB.size()-strA.size(),'0'); string strC; string res; strC.resize(max(strA.size(),strB.size())); dfs(strA,strB,strC,0,0,K,res); bool isok = false; for(int i=0;i<res.size();i++){ if(res[i] != '0') isok = true; if(isok) cout << res[i]; } cout << endl; } } ```
#include <iostream> #include <iomanip> #include <sstream> #include <cstdio> #include <string> #include <vector> #include <algorithm> #include <complex> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #include <climits> #include <queue> #include <set> #include <map> #include <valarray> #include <bitset> #include <stack> using namespace std; #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef pair<int,int> pii; const int INF = 1<<29; const double PI = acos(-1); const double EPS = 1e-8; int main() { string A, B; cin >> A>> B; ll K; cin >> K; ll n = A.size(); ll m = B.size(); if (A.size() < B.size()) { A = string(m-n, '0') + A; } else { B = string(n-m, '0') + B; } n = max(n, m); ll ans = -(1LL<<50); for (ll i=0; i<min(K,n); ++i) { string perm = string(n-i-1, '0') + string(i+1, '1'); do { ll borrow = 0; ll hoge = 1; ll tmp = 0; for (ll i=n-1; i>=0; --i) { ll a = A[i]-'0'; ll b = B[i]-'0'; ll C; if (a-borrow>=b) { C = a-borrow-b; borrow = 0; } else { C = a-borrow+10-b; borrow = 1; } if (perm[i] == '1') { borrow = 0; } tmp += hoge*C; hoge *= 10; } ans = max(ans, tmp); }while(next_permutation(ALL(perm))); } cout << ans << endl; }
### Prompt Develop a solution in CPP to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <iomanip> #include <sstream> #include <cstdio> #include <string> #include <vector> #include <algorithm> #include <complex> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #include <climits> #include <queue> #include <set> #include <map> #include <valarray> #include <bitset> #include <stack> using namespace std; #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef pair<int,int> pii; const int INF = 1<<29; const double PI = acos(-1); const double EPS = 1e-8; int main() { string A, B; cin >> A>> B; ll K; cin >> K; ll n = A.size(); ll m = B.size(); if (A.size() < B.size()) { A = string(m-n, '0') + A; } else { B = string(n-m, '0') + B; } n = max(n, m); ll ans = -(1LL<<50); for (ll i=0; i<min(K,n); ++i) { string perm = string(n-i-1, '0') + string(i+1, '1'); do { ll borrow = 0; ll hoge = 1; ll tmp = 0; for (ll i=n-1; i>=0; --i) { ll a = A[i]-'0'; ll b = B[i]-'0'; ll C; if (a-borrow>=b) { C = a-borrow-b; borrow = 0; } else { C = a-borrow+10-b; borrow = 1; } if (perm[i] == '1') { borrow = 0; } tmp += hoge*C; hoge *= 10; } ans = max(ans, tmp); }while(next_permutation(ALL(perm))); } cout << ans << endl; } ```
#include<iostream> #include<vector> #include<cassert> #include<cmath> using namespace std; long long A,B,K; long long calc(const string& s){ long long a = A, b = B, c = 0, borrow = 0; int base = 1; int N = (int)log10(A)+1; for(int i = 0; i < N; i++){ long long tmpA = a%10; long long tmpB = b%10; a /= 10; b /= 10; if(tmpA - borrow >= tmpB){ c += (tmpA-borrow-tmpB)*base; borrow = 0; base*=10; }else{ c += (tmpA - borrow + 10 - tmpB)*base; if(s[i] == '1') borrow = 0; else borrow = 1; base*=10; } } return c; } long long rec(long long k, const string& s){ if(s.length() == ((int)log10(A)+1)) return calc(s); if(k) return max(rec(k-1,s+"1"),rec(k,s+"0")); return rec(k,s+"0"); } int main(){ cin >> A >> B >> K; cout << rec(K,"") << endl; return 0; }
### Prompt Develop a solution in cpp to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<iostream> #include<vector> #include<cassert> #include<cmath> using namespace std; long long A,B,K; long long calc(const string& s){ long long a = A, b = B, c = 0, borrow = 0; int base = 1; int N = (int)log10(A)+1; for(int i = 0; i < N; i++){ long long tmpA = a%10; long long tmpB = b%10; a /= 10; b /= 10; if(tmpA - borrow >= tmpB){ c += (tmpA-borrow-tmpB)*base; borrow = 0; base*=10; }else{ c += (tmpA - borrow + 10 - tmpB)*base; if(s[i] == '1') borrow = 0; else borrow = 1; base*=10; } } return c; } long long rec(long long k, const string& s){ if(s.length() == ((int)log10(A)+1)) return calc(s); if(k) return max(rec(k-1,s+"1"),rec(k,s+"0")); return rec(k,s+"0"); } int main(){ cin >> A >> B >> K; cout << rec(K,"") << endl; return 0; } ```
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; void solve(const string& A, const string& B, string C, vector<int> borrow, int i, int k, int n, int& ans){ if( i == n ){ int res = 0; reverse(C.begin(),C.end()); for(int i=0 ; i < C.size() ; i++ ){ res = res * 10 + C[i] - '0'; } ans = max( ans , res ); return ; } int a = A[i] - '0'; int b = B[i] - '0'; if( a - borrow[i] >= b ){ C[i] = (a - borrow[i] - b) + '0'; borrow[i+1] = 0; solve(A, B, C, borrow, i+1, k, n, ans); }else{ C[i] = (a - borrow[i] + 10 - b) + '0'; if( k ){ borrow[i+1] = 0; solve(A, B, C, borrow, i+1, k-1, n, ans); } borrow[i+1] = 1; solve(A, B, C, borrow, i+1, k, n, ans); } } int main(){ string A, B; int k; cin >> A >> B >> k; while( B.size() < A.size() ) B = "0" + B; reverse(A.begin(),A.end()); reverse(B.begin(),B.end()); string C; for(int i=0 ; i < A.size() ; i++ ) C.push_back('0'); vector<int> borrow(A.size()+1, 0); int ans = 0; solve(A, B, C, borrow, 0, k, A.size(), ans); cout << ans << endl; }
### Prompt Please formulate a Cpp solution to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; void solve(const string& A, const string& B, string C, vector<int> borrow, int i, int k, int n, int& ans){ if( i == n ){ int res = 0; reverse(C.begin(),C.end()); for(int i=0 ; i < C.size() ; i++ ){ res = res * 10 + C[i] - '0'; } ans = max( ans , res ); return ; } int a = A[i] - '0'; int b = B[i] - '0'; if( a - borrow[i] >= b ){ C[i] = (a - borrow[i] - b) + '0'; borrow[i+1] = 0; solve(A, B, C, borrow, i+1, k, n, ans); }else{ C[i] = (a - borrow[i] + 10 - b) + '0'; if( k ){ borrow[i+1] = 0; solve(A, B, C, borrow, i+1, k-1, n, ans); } borrow[i+1] = 1; solve(A, B, C, borrow, i+1, k, n, ans); } } int main(){ string A, B; int k; cin >> A >> B >> k; while( B.size() < A.size() ) B = "0" + B; reverse(A.begin(),A.end()); reverse(B.begin(),B.end()); string C; for(int i=0 ; i < A.size() ; i++ ) C.push_back('0'); vector<int> borrow(A.size()+1, 0); int ans = 0; solve(A, B, C, borrow, 0, k, A.size(), ans); cout << ans << endl; } ```
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <utility> #include <cstring> #include <iomanip> #include <numeric> #include <limits> #include <cmath> #include <cassert> using namespace std; using ll = long long; const int INF = 1<<30; const int MOD = (int)1e9 + 7; const int MAX_N = (int)1e5 + 5; #define debug(x) cout << #x << ": " << x << endl template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; } string A, B; int K, ans; int to_int(char ch) { return ch - '0'; } void dfs(int pos, int down, int cnt, string result) { if(pos >= A.size()) { reverse(result.begin(), result.end()); ans = max(ans, stoi(result)); return; } int c = to_int(A[pos]) - down - to_int(B[pos]); if(c >= 0) { result += to_string(c); dfs(pos + 1, 0, cnt, result); } else { result += to_string(c + 10); if(cnt > 0) dfs(pos + 1, 0, cnt - 1, result); dfs(pos + 1, 1, cnt, result); } } signed main(void) { cin.tie(0); ios::sync_with_stdio(false); ans = 0; cin >> A >> B >> K; reverse(A.begin(), A.end()); reverse(B.begin(), B.end()); while(A.size() != B.size()) B += '0'; dfs(0, 0, K, ""); cout << ans << endl; return 0; }
### Prompt Please provide a Cpp coded solution to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <utility> #include <cstring> #include <iomanip> #include <numeric> #include <limits> #include <cmath> #include <cassert> using namespace std; using ll = long long; const int INF = 1<<30; const int MOD = (int)1e9 + 7; const int MAX_N = (int)1e5 + 5; #define debug(x) cout << #x << ": " << x << endl template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; } string A, B; int K, ans; int to_int(char ch) { return ch - '0'; } void dfs(int pos, int down, int cnt, string result) { if(pos >= A.size()) { reverse(result.begin(), result.end()); ans = max(ans, stoi(result)); return; } int c = to_int(A[pos]) - down - to_int(B[pos]); if(c >= 0) { result += to_string(c); dfs(pos + 1, 0, cnt, result); } else { result += to_string(c + 10); if(cnt > 0) dfs(pos + 1, 0, cnt - 1, result); dfs(pos + 1, 1, cnt, result); } } signed main(void) { cin.tie(0); ios::sync_with_stdio(false); ans = 0; cin >> A >> B >> K; reverse(A.begin(), A.end()); reverse(B.begin(), B.end()); while(A.size() != B.size()) B += '0'; dfs(0, 0, K, ""); cout << ans << endl; return 0; } ```
#include<iostream> #include<vector> #include<algorithm> #define pb push_back using namespace std; int A,B,K; vector<int> a,b; int rec(int p,int t,int B,vector<int> c){ if(p==a.size()){ int res = 0; int k = 1; for(int i=0;i<(int)c.size();i++){ res += k*c[i]; k *= 10; } return res; } int res = 0; if(a[p]-B>=b[p]){ c.pb(a[p]-B-b[p]); B = 0; }else{ c.pb(a[p]-B-b[p]+10); B = 1; } if(t<K && B==1){ res = max(res,rec(p+1,t+1,0,c)); } res = max(res,rec(p+1,t,B,c)); return res; } int main(){ cin >> A >> B >> K; while(A>0){ a.pb(A%10); A/=10; } while(B>0){ b.pb(B%10); B/=10; } while(b.size()<a.size())b.pb(0); vector<int> c; cout << rec(0,0,0,c) << endl; }
### Prompt Please formulate a cpp solution to the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<iostream> #include<vector> #include<algorithm> #define pb push_back using namespace std; int A,B,K; vector<int> a,b; int rec(int p,int t,int B,vector<int> c){ if(p==a.size()){ int res = 0; int k = 1; for(int i=0;i<(int)c.size();i++){ res += k*c[i]; k *= 10; } return res; } int res = 0; if(a[p]-B>=b[p]){ c.pb(a[p]-B-b[p]); B = 0; }else{ c.pb(a[p]-B-b[p]+10); B = 1; } if(t<K && B==1){ res = max(res,rec(p+1,t+1,0,c)); } res = max(res,rec(p+1,t,B,c)); return res; } int main(){ cin >> A >> B >> K; while(A>0){ a.pb(A%10); A/=10; } while(B>0){ b.pb(B%10); B/=10; } while(b.size()<a.size())b.pb(0); vector<int> c; cout << rec(0,0,0,c) << endl; } ```
#include<cstdio> #include<cstring> #include<algorithm> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int len; char a[16],b[16],c[16]; int dfs(int i,int k,int borrow){ int res=0; rep(_,2){ if(i==len){ if(borrow==0){ reverse(c,c+len); res=max(res,atoi(c)); reverse(c,c+len); } } else{ if(a[i]-borrow>=b[i]){ c[i]=a[i]-borrow-b[i]+'0'; res=max(res,dfs(i+1,k,0)); } else{ c[i]=a[i]-borrow+10-b[i]+'0'; res=max(res,dfs(i+1,k,1)); } } if(borrow==1 && k>0){ borrow=0; k--; } else break; } return res; } int main(){ int k; scanf("%s%s%d",a,b,&k); len=strlen(a); reverse(a,a+len); reverse(b,b+strlen(b)); for(int i=strlen(b);i<len;i++) b[i]='0'; printf("%d\n",dfs(0,k,0)); return 0; }
### Prompt Develop a solution in CPP to the problem described below: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp #include<cstdio> #include<cstring> #include<algorithm> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int len; char a[16],b[16],c[16]; int dfs(int i,int k,int borrow){ int res=0; rep(_,2){ if(i==len){ if(borrow==0){ reverse(c,c+len); res=max(res,atoi(c)); reverse(c,c+len); } } else{ if(a[i]-borrow>=b[i]){ c[i]=a[i]-borrow-b[i]+'0'; res=max(res,dfs(i+1,k,0)); } else{ c[i]=a[i]-borrow+10-b[i]+'0'; res=max(res,dfs(i+1,k,1)); } } if(borrow==1 && k>0){ borrow=0; k--; } else break; } return res; } int main(){ int k; scanf("%s%s%d",a,b,&k); len=strlen(a); reverse(a,a+len); reverse(b,b+strlen(b)); for(int i=strlen(b);i<len;i++) b[i]='0'; printf("%d\n",dfs(0,k,0)); return 0; } ```
//37 #include<iostream> #include<string> #include<cstdlib> using namespace std; int main(){ string a,b; int k; cin>>a>>b>>k; b=string(a.size()-b.size(),'0')+b; string r; for(int i=0;i<1<<a.size();i++){ int bt=0,ic=i; while(ic){ bt++; ic=ic&ic-1; } if(bt<=k){ int c=0; string cr(a.size(),' '); for(int j=a.size()-1;j>=0;j--){ c=c&&!(i>>j&1); if(a[j]-c>=b[j]){ cr[j]=a[j]-c-b[j]+'0'; c=0; }else{ cr[j]=a[j]-c-b[j]+10+'0'; c=1; } } if(r<cr){ r=cr; } } } cout<<atoi(r.c_str())<<endl; return 0; }
### Prompt Create a solution in CPP for the following problem: Problem statement There are two integers $ A $ and $ B $. The process of finding $ A --B $ by writing in decimal is shown below. 1. Express $ A $ and $ B $ in decimal. Subscripts are $ 0,1,2, ..., n-1 $ in order from the bottom, $ A = A_ {n-1} A_ {n-2} ... A_ {0} $, $ B = B_ { n-1} B_ {n-2} ... B_ {0} $. $ n $ is the number of digits of $ A $ when expressed in decimal. When the number of digits of $ B $ is less than $ n $, the upper digit is supplemented with $ 0 $. 2. Set $ ​​borrow_ {0} = 0 $. 3. Repeat the following process from $ i = 0 $ to $ n-1 $. 3.1. If $ A_ {i} --borrow_ {i} \ geq B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} --B_ {i} $, $ borrow_ {i + 1 } = 0 $. 3.2. If $ A_ {i} --borrow_ {i} \ lt B_ {i} $, then $ C_ {i} = A_ {i} --borrow_ {i} + 10 --B_ {i} $, $ borrow_ {i Let +1} = 1 $. The calculation result of $ A --B $ is $ C_ {n-1} C_ {n-2} ... C_ {0} $. However, the top-level consecutive $ 0 $ is removed. If you forget to carry down, $ borrow_ {i + 1} = 1 $ in the process of 3.2 becomes $ borrow_ {i + 1} = 0 $. Find the maximum value of the calculation result when you forget to carry down the maximum $ K $ times. Constraint * $ 1 \ leq B \ lt A \ leq 10 ^ 9 $ * $ 1 \ leq K \ leq 9 $ input Input follows the following format. All given numbers are integers. $ A $ $ B $ $ K $ output Output the maximum value of the calculation result on one line. Examples Input 99 98 1 Output 1 Input 100 2 3 Output 198 Input 538 84 1 Output 554 Input 2012 1987 1 Output 1025 ### Response ```cpp //37 #include<iostream> #include<string> #include<cstdlib> using namespace std; int main(){ string a,b; int k; cin>>a>>b>>k; b=string(a.size()-b.size(),'0')+b; string r; for(int i=0;i<1<<a.size();i++){ int bt=0,ic=i; while(ic){ bt++; ic=ic&ic-1; } if(bt<=k){ int c=0; string cr(a.size(),' '); for(int j=a.size()-1;j>=0;j--){ c=c&&!(i>>j&1); if(a[j]-c>=b[j]){ cr[j]=a[j]-c-b[j]+'0'; c=0; }else{ cr[j]=a[j]-c-b[j]+10+'0'; c=1; } } if(r<cr){ r=cr; } } } cout<<atoi(r.c_str())<<endl; return 0; } ```
//include //------------------------------------------ #include <bits/stdc++.h> // only for GCC using namespace std; //typedef //------------------------------------------ typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull; //container util //------------------------------------------ #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define mp make_pair //repetition //------------------------------------------ #define loop(i,a,b) for(ull i=(a);i<ull(b);++i) #define rep(i,n) loop(i,0,n) #define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i) //constant //-------------------------------------------- const double eps = 1e-10; const double pi = acos(-1.0); const double inf = (int)1e8; // output vector // ------------------------------------------ namespace std { template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){ iter(it,v) os<<*it<<(it+1==v.end()?"":","); return os; } template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){ return os << "[" << p.dirst << "," << p.second << "]"; } } //clear memory // ------------------------------------------ #define clr(a,i) memset((a), (i) ,sizeof(a)) int main(){ int n,t; int h1,m1,h2,m2; char c; string s; vs a; vi ans; cin >> n >> t; rep(i,n){ cin>>h1>>c>>m1>>s; if(i!=0)if((h1-h2)*60+(m1-m2)>=t){ a.pb(s); ans.pb((h1-h2)*60+(m1-m2)); } cin>>h2>>c>>m2>>s; } cout << a.size() << endl; rep(i,a.size()) cout << a[i] << " " << ans[i] << endl; }
### Prompt Construct a Cpp code solution to the problem outlined: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp //include //------------------------------------------ #include <bits/stdc++.h> // only for GCC using namespace std; //typedef //------------------------------------------ typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull; //container util //------------------------------------------ #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define mp make_pair //repetition //------------------------------------------ #define loop(i,a,b) for(ull i=(a);i<ull(b);++i) #define rep(i,n) loop(i,0,n) #define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i) //constant //-------------------------------------------- const double eps = 1e-10; const double pi = acos(-1.0); const double inf = (int)1e8; // output vector // ------------------------------------------ namespace std { template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){ iter(it,v) os<<*it<<(it+1==v.end()?"":","); return os; } template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){ return os << "[" << p.dirst << "," << p.second << "]"; } } //clear memory // ------------------------------------------ #define clr(a,i) memset((a), (i) ,sizeof(a)) int main(){ int n,t; int h1,m1,h2,m2; char c; string s; vs a; vi ans; cin >> n >> t; rep(i,n){ cin>>h1>>c>>m1>>s; if(i!=0)if((h1-h2)*60+(m1-m2)>=t){ a.pb(s); ans.pb((h1-h2)*60+(m1-m2)); } cin>>h2>>c>>m2>>s; } cout << a.size() << endl; rep(i,a.size()) cout << a[i] << " " << ans[i] << endl; } ```
#include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> using namespace std; int conv(string s){ return atoi(s.substr(0, 2).c_str()) * 60 + atoi(s.substr(3).c_str()); } int main(){ int n, t; cin >> n >> t; vector<pair<string, int> > ans; string pre; for(int i=0;i<n;i++){ string a, b, c, d; cin >> a >> b >> c >> d; if(i){ int tmp = conv(a) - conv(pre); if(tmp >= t) ans.push_back(make_pair(b, tmp)); } pre = c; } cout << ans.size() << endl; for(int i=0;i<ans.size();i++) cout << ans[i].first << ' ' << ans[i].second << endl; return 0; }
### Prompt Create a solution in cpp for the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> using namespace std; int conv(string s){ return atoi(s.substr(0, 2).c_str()) * 60 + atoi(s.substr(3).c_str()); } int main(){ int n, t; cin >> n >> t; vector<pair<string, int> > ans; string pre; for(int i=0;i<n;i++){ string a, b, c, d; cin >> a >> b >> c >> d; if(i){ int tmp = conv(a) - conv(pre); if(tmp >= t) ans.push_back(make_pair(b, tmp)); } pre = c; } cout << ans.size() << endl; for(int i=0;i<ans.size();i++) cout << ans[i].first << ' ' << ans[i].second << endl; return 0; } ```
#include<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) range(i,0,b) #define pb(a) push_back(a) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; #define INF (1 << 31 - 1) using namespace std; typedef struct{ string name; int time; }s; int main(){ int n, t, h, m; string name; char g; map<string, int> sta; vector<s> v; cin >> n >> t; rep(i,n * 2){ cin >> h >> g >> m >> name; int time = h * 60 + m; if(sta[name] == 0) sta[name] = time; else{ int a = time - sta[name]; if(a >= t){ s temp; temp.name = name; temp.time = a; v.pb(temp); } } } cout << v.size() << endl; rep(i,v.size()){ if(v[i].time >= t){ cout << v[i].name << ' ' << v[i].time << endl; } } }
### Prompt In CPP, your task is to solve the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) range(i,0,b) #define pb(a) push_back(a) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; #define INF (1 << 31 - 1) using namespace std; typedef struct{ string name; int time; }s; int main(){ int n, t, h, m; string name; char g; map<string, int> sta; vector<s> v; cin >> n >> t; rep(i,n * 2){ cin >> h >> g >> m >> name; int time = h * 60 + m; if(sta[name] == 0) sta[name] = time; else{ int a = time - sta[name]; if(a >= t){ s temp; temp.name = name; temp.time = a; v.pb(temp); } } } cout << v.size() << endl; rep(i,v.size()){ if(v[i].time >= t){ cout << v[i].name << ' ' << v[i].time << endl; } } } ```
#include<bits/stdc++.h> using namespace std; int a(char x){ return x-'0'; } int cal(string s){ int h = a(s[0])*10 + a(s[1]), m = a(s[3])*10 + a(s[4]); return h*60+m; } int main(){ int n,t; cin >> n >> t; vector<string> ansn; vector<int> anst; int bt = -1; for(int i=0;i<n;i++){ string st, sn, et, en; cin >> st >> sn >> et >> en; int at = cal(st); if(i>0){ if(at-bt >= t){ ansn.push_back(sn); anst.push_back(at-bt); } } bt = cal(et); } cout << ansn.size() << endl; for(int i=0;i<(int)ansn.size();i++){ cout << ansn[i] << " " << anst[i] << endl; } }
### Prompt Your challenge is to write a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<bits/stdc++.h> using namespace std; int a(char x){ return x-'0'; } int cal(string s){ int h = a(s[0])*10 + a(s[1]), m = a(s[3])*10 + a(s[4]); return h*60+m; } int main(){ int n,t; cin >> n >> t; vector<string> ansn; vector<int> anst; int bt = -1; for(int i=0;i<n;i++){ string st, sn, et, en; cin >> st >> sn >> et >> en; int at = cal(st); if(i>0){ if(at-bt >= t){ ansn.push_back(sn); anst.push_back(at-bt); } } bt = cal(et); } cout << ansn.size() << endl; for(int i=0;i<(int)ansn.size();i++){ cout << ansn[i] << " " << anst[i] << endl; } } ```
#include <bits/stdc++.h> #define r(i,a,n) for(int i=a;i<n;i++) using namespace std; int main(){ int n,t,cc=0,aa[11514]; string sss[11514],pp; cin>>n>>t; if(n)cin>>pp>>pp; r(i,0,n-1){ int a,b,c,d; string s,ss; scanf("%d:%d",&a,&b); cin>>s; scanf("%d:%d",&c,&d); cin>>ss; if(((c*60+d)-(a*60+b))>=t){ sss[cc]=ss; aa[cc++]=(c*60+d)-(a*60+b); } } if(n)cin>>pp>>pp; cout<<cc<<endl; r(i,0,cc)cout<<sss[i]<<' '<<aa[i]<<endl; }
### Prompt Construct a CPP code solution to the problem outlined: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <bits/stdc++.h> #define r(i,a,n) for(int i=a;i<n;i++) using namespace std; int main(){ int n,t,cc=0,aa[11514]; string sss[11514],pp; cin>>n>>t; if(n)cin>>pp>>pp; r(i,0,n-1){ int a,b,c,d; string s,ss; scanf("%d:%d",&a,&b); cin>>s; scanf("%d:%d",&c,&d); cin>>ss; if(((c*60+d)-(a*60+b))>=t){ sss[cc]=ss; aa[cc++]=(c*60+d)-(a*60+b); } } if(n)cin>>pp>>pp; cout<<cc<<endl; r(i,0,cc)cout<<sss[i]<<' '<<aa[i]<<endl; } ```
#include <iostream> #include <sstream> #include <string> #include <vector> #include <map> using namespace std; int main(){ int n,t,tim1,sec1,tim2,sec2,tot1,tot2; string s,na1,na2; char trash; stringstream ss; vector <pair<string,int> > ans; cin >> n >> t; cin.ignore(); getline(cin,s); ss << s; ss>>tim1>>trash>>sec1>>na1>>tim2>>trash>>sec2>>na2; tot1 = tim2*60 + sec2; for(int i=1;i<n;i++){ ss.clear(); getline(cin,s); ss << s; ss>>tim1>>trash>>sec1>>na1>>tim2>>trash>>sec2>>na2; tot2 = tim1*60 + sec1; if(tot2 - tot1 >= t) ans.push_back(make_pair(na1,tot2-tot1)); tot1 = tim2*60 + sec2; } cout << ans.size() << endl; for(int i=0;i<ans.size();i++){ cout << ans[i].first << " " << ans[i].second << endl; } }
### Prompt Please create a solution in CPP to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <sstream> #include <string> #include <vector> #include <map> using namespace std; int main(){ int n,t,tim1,sec1,tim2,sec2,tot1,tot2; string s,na1,na2; char trash; stringstream ss; vector <pair<string,int> > ans; cin >> n >> t; cin.ignore(); getline(cin,s); ss << s; ss>>tim1>>trash>>sec1>>na1>>tim2>>trash>>sec2>>na2; tot1 = tim2*60 + sec2; for(int i=1;i<n;i++){ ss.clear(); getline(cin,s); ss << s; ss>>tim1>>trash>>sec1>>na1>>tim2>>trash>>sec2>>na2; tot2 = tim1*60 + sec1; if(tot2 - tot1 >= t) ans.push_back(make_pair(na1,tot2-tot1)); tot1 = tim2*60 + sec2; } cout << ans.size() << endl; for(int i=0;i<ans.size();i++){ cout << ans[i].first << " " << ans[i].second << endl; } } ```
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <string> #include <map> #include <queue> #include <stack> #include <algorithm> #define rep(i,j) REP((i), 0, (j)) #define REP(i,j,k) for(int i=(j);(i)<(k);++i) #define between(a,x,b) ((a)<=(x)&&(x)<=(b)) using namespace std; int N, T; int main(){ int h1, m1, h2, m2; char st[51], ar[51]; char s[10][51]; scanf("%d%d", &N, &T); vector<pair<int, int> >time(N); rep(i, N){ scanf("%d:%d%s%d:%d%s", &h1, &m1, s[i], &h2, &m2, ar); time[i] = make_pair(h1*60+m1, h2*60+m2); } int M = 0; vector<pair<string, int> >res(N); REP(i, 1, N){ int trip = time[i].first - time[i-1].second; if(trip < T) continue; res[M] = make_pair(string(s[i]), trip); M++; } printf("%d\n", M); rep(i, M) printf("%s %d\n", res[i].first.c_str(), res[i].second); return 0; }
### Prompt Create a solution in Cpp for the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <string> #include <map> #include <queue> #include <stack> #include <algorithm> #define rep(i,j) REP((i), 0, (j)) #define REP(i,j,k) for(int i=(j);(i)<(k);++i) #define between(a,x,b) ((a)<=(x)&&(x)<=(b)) using namespace std; int N, T; int main(){ int h1, m1, h2, m2; char st[51], ar[51]; char s[10][51]; scanf("%d%d", &N, &T); vector<pair<int, int> >time(N); rep(i, N){ scanf("%d:%d%s%d:%d%s", &h1, &m1, s[i], &h2, &m2, ar); time[i] = make_pair(h1*60+m1, h2*60+m2); } int M = 0; vector<pair<string, int> >res(N); REP(i, 1, N){ int trip = time[i].first - time[i-1].second; if(trip < T) continue; res[M] = make_pair(string(s[i]), trip); M++; } printf("%d\n", M); rep(i, M) printf("%s %d\n", res[i].first.c_str(), res[i].second); return 0; } ```
#include <iostream> #include <vector> #include <map> using namespace std; typedef pair<string, int> P; int main(){ int n, t; vector<P> v; cin >> n >> t; int h1, m1, h2, m2; char c; string str; cin >> h1 >> c >> m1 >> str; if( n == 1 ) { cout << 0 << endl; return 0; } for(int i=0; i<n; i++) { cin >> h1 >> c >> m1 >> str; cin >> h2 >> c >> m2 >> str; int A = h2*60+m2 - (h1*60+m1); if( A >= t ) { v.push_back( make_pair( str, A ) ); } } cout << v.size() << endl; for(int i=0; i<v.size(); i++) { cout << v[i].first << " " << v[i].second << endl; } return 0; }
### Prompt Construct a Cpp code solution to the problem outlined: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <vector> #include <map> using namespace std; typedef pair<string, int> P; int main(){ int n, t; vector<P> v; cin >> n >> t; int h1, m1, h2, m2; char c; string str; cin >> h1 >> c >> m1 >> str; if( n == 1 ) { cout << 0 << endl; return 0; } for(int i=0; i<n; i++) { cin >> h1 >> c >> m1 >> str; cin >> h2 >> c >> m2 >> str; int A = h2*60+m2 - (h1*60+m1); if( A >= t ) { v.push_back( make_pair( str, A ) ); } } cout << v.size() << endl; for(int i=0; i<v.size(); i++) { cout << v[i].first << " " << v[i].second << endl; } return 0; } ```
#include<iostream> #include<vector> using namespace std; int main() { int n,t; cin>>n>>t; int at; vector<int> ii; vector<string> ss; for(int i=0;i<n;i++) { int st_t1,st_t2,ar_t1,ar_t2; string st_n,ar_n; char br; cin>>st_t1>>br>>st_t2>>st_n>>ar_t1>>br>>ar_t2>>ar_n; if(i>0 && (st_t1*60+st_t2)-at>=t) { ii.push_back((st_t1*60+st_t2)-at); ss.push_back(st_n); } at=ar_t1*60+ar_t2; } cout<<ii.size()<<endl; for(int i=0;i<ii.size();i++) { cout<<ss[i]<<" "<<ii[i]<<endl; } }
### Prompt Please create a solution in CPP to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<vector> using namespace std; int main() { int n,t; cin>>n>>t; int at; vector<int> ii; vector<string> ss; for(int i=0;i<n;i++) { int st_t1,st_t2,ar_t1,ar_t2; string st_n,ar_n; char br; cin>>st_t1>>br>>st_t2>>st_n>>ar_t1>>br>>ar_t2>>ar_n; if(i>0 && (st_t1*60+st_t2)-at>=t) { ii.push_back((st_t1*60+st_t2)-at); ss.push_back(st_n); } at=ar_t1*60+ar_t2; } cout<<ii.size()<<endl; for(int i=0;i<ii.size();i++) { cout<<ss[i]<<" "<<ii[i]<<endl; } } ```
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) int N,T; vector<pair<string,int> > ans; inline int conv(int hh,int mm) { return hh*60+mm; } int main() { cin>>N>>T; int hh1,mm1,hh2,mm2; string st_name,ar_name; scanf("%d:%d",&hh1,&mm1); cin>>st_name; rep(i,N-1) { scanf("%d:%d",&hh1,&mm1); cin>>st_name; scanf("%d:%d",&hh2,&mm2); cin>>ar_name; int t = conv(hh2,mm2)-conv(hh1,mm1); if(t>=T) { ans.push_back(make_pair(st_name,t)); } } scanf("%d:%d",&mm1,&hh1); cin>>st_name; cout<<ans.size()<<endl; rep(i,ans.size()) { cout<<ans[i].first<<" "<<ans[i].second<<endl; } return 0; }
### Prompt Generate a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) int N,T; vector<pair<string,int> > ans; inline int conv(int hh,int mm) { return hh*60+mm; } int main() { cin>>N>>T; int hh1,mm1,hh2,mm2; string st_name,ar_name; scanf("%d:%d",&hh1,&mm1); cin>>st_name; rep(i,N-1) { scanf("%d:%d",&hh1,&mm1); cin>>st_name; scanf("%d:%d",&hh2,&mm2); cin>>ar_name; int t = conv(hh2,mm2)-conv(hh1,mm1); if(t>=T) { ans.push_back(make_pair(st_name,t)); } } scanf("%d:%d",&mm1,&hh1); cin>>st_name; cout<<ans.size()<<endl; rep(i,ans.size()) { cout<<ans[i].first<<" "<<ans[i].second<<endl; } return 0; } ```
#include <cstdio> #include <iostream> #include <string> #include <map> #include <vector> using namespace std; typedef pair<string,int> psi; vector<psi> stay; int main(void){ int n,t; cin >> n >> t; int prev=-1; for(int i=0;i<n;++i){ string st,sn,at,an; cin >> st >> sn >> at >> an; int sh=10*(st[0]-'0')+(st[1]-'0'); int sm=10*(st[3]-'0')+(st[4]-'0'); int s=sh*60+sm; int ah=10*(at[0]-'0')+(at[1]-'0'); int am=10*(at[3]-'0')+(at[4]-'0'); int a=ah*60+am; if(prev!=-1&&s-prev>=t) stay.push_back(make_pair(sn,s-prev)); prev=a; } cout << stay.size() << endl; for(int i=0;i<stay.size();++i) cout << stay[i].first << " " << stay[i].second << endl; return 0; }
### Prompt Your task is to create a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <cstdio> #include <iostream> #include <string> #include <map> #include <vector> using namespace std; typedef pair<string,int> psi; vector<psi> stay; int main(void){ int n,t; cin >> n >> t; int prev=-1; for(int i=0;i<n;++i){ string st,sn,at,an; cin >> st >> sn >> at >> an; int sh=10*(st[0]-'0')+(st[1]-'0'); int sm=10*(st[3]-'0')+(st[4]-'0'); int s=sh*60+sm; int ah=10*(at[0]-'0')+(at[1]-'0'); int am=10*(at[3]-'0')+(at[4]-'0'); int a=ah*60+am; if(prev!=-1&&s-prev>=t) stay.push_back(make_pair(sn,s-prev)); prev=a; } cout << stay.size() << endl; for(int i=0;i<stay.size();++i) cout << stay[i].first << " " << stay[i].second << endl; return 0; } ```
#include<vector> #include<map> #include<climits> #include<set> #include<queue> #include<algorithm> #include<functional> #include<numeric> #include<utility> #include<sstream> #include<iostream> #include<iomanip> #include<cstdio> #include<cmath> #include<cstdlib> #include<cctype> #include<string> #include<bitset> #include<cstring> #include<list> using namespace std; typedef vector<int>VI; typedef vector<VI>VVI; typedef vector<string>VS; typedef pair<int,int>PII; typedef long long LL; typedef pair<LL,LL>PLL; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define PB push_back #define EACH(i,c) for(typeof((c).begin())i=(c).begin();i!=(c).end();i++) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define F first #define S second int main(){ int N,T;scanf("%d%d",&N,&T); char str[100]; int t,m; scanf("%d:%d%s",&t,&m,str); vector<pair<string,int> >V; REP(i,N-1){ scanf("%d:%d%s",&t,&m,str); int val=t*60+m; scanf("%d:%d%s",&t,&m,str); int v2=t*60+m; v2-=val; string s=str; if(v2>=T)V.PB(pair<string,int>(s,v2)); } cout<<V.size()<<endl; REP(i,V.size()){ cout<<V[i].first<<" "<<V[i].second<<endl; } return 0; }
### Prompt Your task is to create a cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<vector> #include<map> #include<climits> #include<set> #include<queue> #include<algorithm> #include<functional> #include<numeric> #include<utility> #include<sstream> #include<iostream> #include<iomanip> #include<cstdio> #include<cmath> #include<cstdlib> #include<cctype> #include<string> #include<bitset> #include<cstring> #include<list> using namespace std; typedef vector<int>VI; typedef vector<VI>VVI; typedef vector<string>VS; typedef pair<int,int>PII; typedef long long LL; typedef pair<LL,LL>PLL; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define PB push_back #define EACH(i,c) for(typeof((c).begin())i=(c).begin();i!=(c).end();i++) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define F first #define S second int main(){ int N,T;scanf("%d%d",&N,&T); char str[100]; int t,m; scanf("%d:%d%s",&t,&m,str); vector<pair<string,int> >V; REP(i,N-1){ scanf("%d:%d%s",&t,&m,str); int val=t*60+m; scanf("%d:%d%s",&t,&m,str); int v2=t*60+m; v2-=val; string s=str; if(v2>=T)V.PB(pair<string,int>(s,v2)); } cout<<V.size()<<endl; REP(i,V.size()){ cout<<V[i].first<<" "<<V[i].second<<endl; } return 0; } ```
#include<bits/stdc++.h> using namespace std; int toMin(string s){ return stoi(s.substr(0,2)) * 60 + stoi(s.substr(3,2)); } int main(){ int N,T; cin >> N >> T; vector<pair<string,int>> ans; string st_time,st_name,ar_time,ar_name; cin >> st_time >> st_name; for(int i = 0;i < N-1;i++){ cin >> ar_time >> ar_name >> st_time >> st_name; if(toMin(st_time) - toMin(ar_time) >= T){ ans.push_back(make_pair(st_name,toMin(st_time) - toMin(ar_time))); } } cin >> ar_time >> ar_name; cout << ans.size() << endl; for(auto p:ans)cout << p.first << ' ' << p.second << endl; }
### Prompt Generate a Cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<bits/stdc++.h> using namespace std; int toMin(string s){ return stoi(s.substr(0,2)) * 60 + stoi(s.substr(3,2)); } int main(){ int N,T; cin >> N >> T; vector<pair<string,int>> ans; string st_time,st_name,ar_time,ar_name; cin >> st_time >> st_name; for(int i = 0;i < N-1;i++){ cin >> ar_time >> ar_name >> st_time >> st_name; if(toMin(st_time) - toMin(ar_time) >= T){ ans.push_back(make_pair(st_name,toMin(st_time) - toMin(ar_time))); } } cin >> ar_time >> ar_name; cout << ans.size() << endl; for(auto p:ans)cout << p.first << ' ' << p.second << endl; } ```
#include <cstdlib> #include <iostream> #include <vector> using namespace std; inline int input_time() { int h, m; char semicolon; cin >> h >> semicolon >> m; return h * 60 + m; } inline string input_name() { string name; cin >> name; return name; } inline void input_null() { string null; cin >> null; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, t; cin >> n >> t; if(n == 1) { cout << 0 << endl; } else { input_null(); input_null(); vector<pair<string, int>> ans; for(int i = 0; i < n - 1; ++i) { const int prev_time = input_time(); const string station_name = input_name(); const int next_time = input_time(); input_null(); const int stay_time = next_time - prev_time; if(stay_time >= t) ans.emplace_back(station_name, stay_time); } cout << ans.size() << endl; for(int i = 0; i < (int)ans.size(); ++i) cout << ans[i].first << " " << ans[i].second << endl; } return EXIT_SUCCESS; }
### Prompt Create a solution in Cpp for the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <cstdlib> #include <iostream> #include <vector> using namespace std; inline int input_time() { int h, m; char semicolon; cin >> h >> semicolon >> m; return h * 60 + m; } inline string input_name() { string name; cin >> name; return name; } inline void input_null() { string null; cin >> null; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, t; cin >> n >> t; if(n == 1) { cout << 0 << endl; } else { input_null(); input_null(); vector<pair<string, int>> ans; for(int i = 0; i < n - 1; ++i) { const int prev_time = input_time(); const string station_name = input_name(); const int next_time = input_time(); input_null(); const int stay_time = next_time - prev_time; if(stay_time >= t) ans.emplace_back(station_name, stay_time); } cout << ans.size() << endl; for(int i = 0; i < (int)ans.size(); ++i) cout << ans[i].first << " " << ans[i].second << endl; } return EXIT_SUCCESS; } ```
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <numeric> #include <stack> #include <queue> #include <map> #include <set> #include <utility> #include <sstream> #include <complex> #include <fstream> using namespace std; #define FOR(i,a,b) for(long long i=(a);i<(b);i++) #define REP(i,N) for(long long i=0;i<(N);i++) #define ALL(s) (s).begin(),(s).end() #define fi first #define se second #define PI acos(-1.0) #define INF 10e9+9 #define EPS 1e-10 #define MAX_N 100100 #define MAX_M 100100 typedef long long ll; typedef pair<ll, ll> P; typedef pair<double, double> PD; typedef pair<string, ll> PS; typedef vector<ll> V; typedef pair<P, char> PC; int n, t; vector<PS> vpi; string s; int h, m; char c; int main(){ cin >> n >> t; PS p; REP(i, n){ if (i == 0){ cin >> s; cin >> s; cin >> h >> c >> m; cin >> s; p = PS(s, h * 60 + m); } else{ cin >> h >> c >> m; cin >> s; if (h * 60 + m - p.second >= t){ vpi.push_back(PS(p.first, h * 60 + m - p.second)); } cin >> h >> c >> m; cin >> s; p = PS(s, h * 60 + m); } } cout << vpi.size() << endl; REP(i, vpi.size()){ cout << vpi[i].first << " " << vpi[i].second << endl; } }
### Prompt Develop a solution in CPP to the problem described below: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <string> #include <vector> #include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <numeric> #include <stack> #include <queue> #include <map> #include <set> #include <utility> #include <sstream> #include <complex> #include <fstream> using namespace std; #define FOR(i,a,b) for(long long i=(a);i<(b);i++) #define REP(i,N) for(long long i=0;i<(N);i++) #define ALL(s) (s).begin(),(s).end() #define fi first #define se second #define PI acos(-1.0) #define INF 10e9+9 #define EPS 1e-10 #define MAX_N 100100 #define MAX_M 100100 typedef long long ll; typedef pair<ll, ll> P; typedef pair<double, double> PD; typedef pair<string, ll> PS; typedef vector<ll> V; typedef pair<P, char> PC; int n, t; vector<PS> vpi; string s; int h, m; char c; int main(){ cin >> n >> t; PS p; REP(i, n){ if (i == 0){ cin >> s; cin >> s; cin >> h >> c >> m; cin >> s; p = PS(s, h * 60 + m); } else{ cin >> h >> c >> m; cin >> s; if (h * 60 + m - p.second >= t){ vpi.push_back(PS(p.first, h * 60 + m - p.second)); } cin >> h >> c >> m; cin >> s; p = PS(s, h * 60 + m); } } cout << vpi.size() << endl; REP(i, vpi.size()){ cout << vpi[i].first << " " << vpi[i].second << endl; } } ```
#include<iostream> #include<string> #include<vector> #include<algorithm> #define Pair pair<int, string> using namespace std; int convert_minutes(const string& s){ int h = (s[0]-'0')*10 + (s[1]-'0'); int m = (s[3]-'0')*10 + (s[4]-'0'); return 60*h + m; } int main(){ int N, T, t, t_; string t1, t2, s1, s2; vector<Pair> ans; cin >> N >> T; for(int i=0; i<N; ++i){ cin >> t1 >> s1 >> t2 >> s2; if(i != 0){ t_ = convert_minutes(t1); if(t_-t >= T) ans.push_back(make_pair(t_-t, s1)); } t = convert_minutes(t2); } cout << ans.size() << endl; for(vector<Pair>::iterator it=ans.begin(); it!=ans.end(); ++it) cout << it->second << " " << it->first << endl; return 0; }
### Prompt Please formulate a cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<string> #include<vector> #include<algorithm> #define Pair pair<int, string> using namespace std; int convert_minutes(const string& s){ int h = (s[0]-'0')*10 + (s[1]-'0'); int m = (s[3]-'0')*10 + (s[4]-'0'); return 60*h + m; } int main(){ int N, T, t, t_; string t1, t2, s1, s2; vector<Pair> ans; cin >> N >> T; for(int i=0; i<N; ++i){ cin >> t1 >> s1 >> t2 >> s2; if(i != 0){ t_ = convert_minutes(t1); if(t_-t >= T) ans.push_back(make_pair(t_-t, s1)); } t = convert_minutes(t2); } cout << ans.size() << endl; for(vector<Pair>::iterator it=ans.begin(); it!=ans.end(); ++it) cout << it->second << " " << it->first << endl; return 0; } ```
#include <iostream> #include <string> #include <sstream> #include <algorithm> #include <vector> #include <utility> #include <functional> #include <stack> #include <queue> #include <map> #include <set> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <deque> #include <ctime> using namespace std; #define rep(i,n) REP(i,0,n) #define REP(i,s,e) for(int i=(s); i<(int)(e); i++) #define pb push_back #define mp make_pair #define all(r) r.begin(),r.end() #define fi first #define se second #define println(X) cout<<X<<endl; #define DBG(X) cout<<#X<<" : "<<X<<endl; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ll> vl; typedef vector<vl> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll MOD = 1e9 + 7; double EPS = 1e-10; int dx[]={-1,0,1,0}; int dy[]={0,-1,0,1}; int main(){ int n, T; cin>>n>>T; int a, b; string t1, t2, n1, n2; vector<pair<string, int> > ans; cin>>t1>>n1; //cout<<n-1<<endl; //cout<<T<<endl; rep(i, n-1){ cin>>t1>>n1>>t2>>n2; //if(n2!=n1) continue; a = b = 0; a = (t1[0]*10+t1[1])*60+t1[3]*10+t1[4]; b = (t2[0]*10+t2[1])*60+t2[3]*10+t2[4]; //cout<<(b-a >= T)<<n1<<endl; if(b-a >= T){ ans.pb(mp(n1, b-a)); } } cin>>t1>>n1; cout<<ans.size()<<endl; rep(i, ans.size()){ cout<<ans[i].fi<<" "<<ans[i].se<<endl; } }
### Prompt Generate a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <string> #include <sstream> #include <algorithm> #include <vector> #include <utility> #include <functional> #include <stack> #include <queue> #include <map> #include <set> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <deque> #include <ctime> using namespace std; #define rep(i,n) REP(i,0,n) #define REP(i,s,e) for(int i=(s); i<(int)(e); i++) #define pb push_back #define mp make_pair #define all(r) r.begin(),r.end() #define fi first #define se second #define println(X) cout<<X<<endl; #define DBG(X) cout<<#X<<" : "<<X<<endl; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ll> vl; typedef vector<vl> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll MOD = 1e9 + 7; double EPS = 1e-10; int dx[]={-1,0,1,0}; int dy[]={0,-1,0,1}; int main(){ int n, T; cin>>n>>T; int a, b; string t1, t2, n1, n2; vector<pair<string, int> > ans; cin>>t1>>n1; //cout<<n-1<<endl; //cout<<T<<endl; rep(i, n-1){ cin>>t1>>n1>>t2>>n2; //if(n2!=n1) continue; a = b = 0; a = (t1[0]*10+t1[1])*60+t1[3]*10+t1[4]; b = (t2[0]*10+t2[1])*60+t2[3]*10+t2[4]; //cout<<(b-a >= T)<<n1<<endl; if(b-a >= T){ ans.pb(mp(n1, b-a)); } } cin>>t1>>n1; cout<<ans.size()<<endl; rep(i, ans.size()){ cout<<ans[i].fi<<" "<<ans[i].se<<endl; } } ```
#define _USE_MATH_DEFINES #define INF 0x3f3f3f3f #include <iostream> #include <cstdio> #include <sstream> #include <cmath> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> #include <bitset> #include <list> #include <cctype> #include <utility> using namespace std; typedef long long ll; typedef pair <int,int> P; typedef pair <int,P> PP; static const double EPS = 1e-8; int tx[] = {0,1,0,-1}; int ty[] = {-1,0,1,0}; struct TimeTable{ int dpt; int arv; }; int main(){ int N,T; while(~scanf("%d %d",&N,&T)){ map<string,TimeTable> trains; vector<string> stations; string start,last; for(int i=0;i<N;i++){ char from[64]; int from_h,from_m; char to[64]; int to_h,to_m; scanf("%d:%d %s %d:%d %s",&from_h,&from_m,from,&to_h,&to_m,to); trains[from].dpt = from_h*60 + from_m; trains[to].arv = to_h*60 + to_m; stations.push_back(from); } vector<string> outputs; for(int i=1;i<stations.size();i++){ if(abs(trains[stations[i]].arv - trains[stations[i]].dpt) >= T){ char buf[128]; sprintf(buf,"%s %d",stations[i].c_str(),abs(trains[stations[i]].arv - trains[stations[i]].dpt)); outputs.push_back(buf); } } cout << outputs.size() << endl; for(int i=0;i<outputs.size();i++){ cout << outputs[i] << endl; } } }
### Prompt Construct a cpp code solution to the problem outlined: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #define _USE_MATH_DEFINES #define INF 0x3f3f3f3f #include <iostream> #include <cstdio> #include <sstream> #include <cmath> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> #include <bitset> #include <list> #include <cctype> #include <utility> using namespace std; typedef long long ll; typedef pair <int,int> P; typedef pair <int,P> PP; static const double EPS = 1e-8; int tx[] = {0,1,0,-1}; int ty[] = {-1,0,1,0}; struct TimeTable{ int dpt; int arv; }; int main(){ int N,T; while(~scanf("%d %d",&N,&T)){ map<string,TimeTable> trains; vector<string> stations; string start,last; for(int i=0;i<N;i++){ char from[64]; int from_h,from_m; char to[64]; int to_h,to_m; scanf("%d:%d %s %d:%d %s",&from_h,&from_m,from,&to_h,&to_m,to); trains[from].dpt = from_h*60 + from_m; trains[to].arv = to_h*60 + to_m; stations.push_back(from); } vector<string> outputs; for(int i=1;i<stations.size();i++){ if(abs(trains[stations[i]].arv - trains[stations[i]].dpt) >= T){ char buf[128]; sprintf(buf,"%s %d",stations[i].c_str(),abs(trains[stations[i]].arv - trains[stations[i]].dpt)); outputs.push_back(buf); } } cout << outputs.size() << endl; for(int i=0;i<outputs.size();i++){ cout << outputs[i] << endl; } } } ```
#define _USE_MATH_DEFINES #include<stdio.h> #include<string> #include<iostream> #include<cctype> #include<cstdio> #include<vector> #include<stack> #include <algorithm> #include<math.h> #include<set> #include<map> #include<iomanip> using namespace std; int main(){ int n,t; cin>>n>>t; pair<string,int>y[15]; int g=0; int ans=0; for(int i=0;i<n;i++){ string a,b,c,d; cin>>a>>b>>c>>d; int w=0,z=0; w=(a[0]-'0')*10+(a[1]-'0'); w*=60; w+=(a[3]-'0')*10+(a[4]-'0'); z=(c[0]-'0')*10+(c[1]-'0'); z*=60; z+=(c[3]-'0')*10+(c[4]-'0'); if(i){ if(w-g>=t){ y[ans].first=b; y[ans].second=w-g; ans++; } } g=z; } cout<<ans<<endl; for(int i=0;i<ans;i++){ cout<<y[i].first<<" "<<y[i].second<<endl; } return 0; }
### Prompt Your task is to create a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #define _USE_MATH_DEFINES #include<stdio.h> #include<string> #include<iostream> #include<cctype> #include<cstdio> #include<vector> #include<stack> #include <algorithm> #include<math.h> #include<set> #include<map> #include<iomanip> using namespace std; int main(){ int n,t; cin>>n>>t; pair<string,int>y[15]; int g=0; int ans=0; for(int i=0;i<n;i++){ string a,b,c,d; cin>>a>>b>>c>>d; int w=0,z=0; w=(a[0]-'0')*10+(a[1]-'0'); w*=60; w+=(a[3]-'0')*10+(a[4]-'0'); z=(c[0]-'0')*10+(c[1]-'0'); z*=60; z+=(c[3]-'0')*10+(c[4]-'0'); if(i){ if(w-g>=t){ y[ans].first=b; y[ans].second=w-g; ans++; } } g=z; } cout<<ans<<endl; for(int i=0;i<ans;i++){ cout<<y[i].first<<" "<<y[i].second<<endl; } return 0; } ```
#include <iostream> #include <string> #include <vector> #include <sstream> using namespace std; const int INF = 1000000000; int get_time(const string &s){ stringstream ss(s); int h, m; ss >> h; ss.ignore(); ss >> m; return h * 60 + m; } int main(){ ios_base::sync_with_stdio(false); int n, t; cin >> n >> t; int prev = INF; vector<string> ans_name; vector<int> ans_time; for(int i = 0; i < n; ++i){ string st_time, st_name, ar_time, ar_name; cin >> st_time >> st_name >> ar_time >> ar_name; const int cur = get_time(st_time); if(prev + t <= cur){ ans_name.push_back(st_name); ans_time.push_back(cur - prev); } prev = get_time(ar_time); } cout << ans_name.size() << endl; for(int i = 0; i < ans_name.size(); ++i){ cout << ans_name[i] << " " << ans_time[i] << endl; } return 0; }
### Prompt Please create a solution in cpp to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <string> #include <vector> #include <sstream> using namespace std; const int INF = 1000000000; int get_time(const string &s){ stringstream ss(s); int h, m; ss >> h; ss.ignore(); ss >> m; return h * 60 + m; } int main(){ ios_base::sync_with_stdio(false); int n, t; cin >> n >> t; int prev = INF; vector<string> ans_name; vector<int> ans_time; for(int i = 0; i < n; ++i){ string st_time, st_name, ar_time, ar_name; cin >> st_time >> st_name >> ar_time >> ar_name; const int cur = get_time(st_time); if(prev + t <= cur){ ans_name.push_back(st_name); ans_time.push_back(cur - prev); } prev = get_time(ar_time); } cout << ans_name.size() << endl; for(int i = 0; i < ans_name.size(); ++i){ cout << ans_name[i] << " " << ans_time[i] << endl; } return 0; } ```
#include <iostream> #include <cstdlib> #include <string> #include <vector> using namespace std; struct Status { int t; // [minute] string name; }; int getTime( string s ) { int m = ( s[ 0 ] - '0' ) * 600 + ( s[ 1 ] - '0' ) * 60; m += ( ( s[ 3 ] - '0' ) * 10 + s[ 4 ] - '0' ); return m; } int main () { int n, t; int prevArr; vector<Status> v; cin >> n >> t; for( int i = 0; i < n; i++ ) { string dt, dep, at, arr; cin >> dt >> dep >> at >> arr; if( i != 0 ) { int tt = getTime( dt ) - prevArr; if( tt >= t ) { Status s; s.t = tt; s.name = dep; v.push_back( s ); } } prevArr = getTime( at ); } int len = v.size(); cout << len << endl; for( int i = 0; i < len; i++ ) { cout << v[ i ].name << " " << v[ i ].t << endl; } return EXIT_SUCCESS; }
### Prompt Construct a cpp code solution to the problem outlined: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <cstdlib> #include <string> #include <vector> using namespace std; struct Status { int t; // [minute] string name; }; int getTime( string s ) { int m = ( s[ 0 ] - '0' ) * 600 + ( s[ 1 ] - '0' ) * 60; m += ( ( s[ 3 ] - '0' ) * 10 + s[ 4 ] - '0' ); return m; } int main () { int n, t; int prevArr; vector<Status> v; cin >> n >> t; for( int i = 0; i < n; i++ ) { string dt, dep, at, arr; cin >> dt >> dep >> at >> arr; if( i != 0 ) { int tt = getTime( dt ) - prevArr; if( tt >= t ) { Status s; s.t = tt; s.name = dep; v.push_back( s ); } } prevArr = getTime( at ); } int len = v.size(); cout << len << endl; for( int i = 0; i < len; i++ ) { cout << v[ i ].name << " " << v[ i ].t << endl; } return EXIT_SUCCESS; } ```
#include<bits/stdc++.h> using namespace std; int main(){ int n,t; scanf("%d%d",&n,&t); vector<string> name; vector<int> stay; int prv = 0; for(int i=0;i<n;i++){ int h1,m1,h2,m2; string name1, name2; scanf("%d:%d",&h1,&m1); m1 += h1*60; cin >> name1; scanf("%d:%d",&h2,&m2); m2 += h2*60; cin >> name2; if(i>0 && m1-prv>=t){ name.push_back(name1); stay.push_back(m1-prv); } prv = m2; } cout << name.size() << endl; for(int i=0;i<name.size();i++){ cout << name[i] << " " << stay[i] << endl; } }
### Prompt In Cpp, your task is to solve the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<bits/stdc++.h> using namespace std; int main(){ int n,t; scanf("%d%d",&n,&t); vector<string> name; vector<int> stay; int prv = 0; for(int i=0;i<n;i++){ int h1,m1,h2,m2; string name1, name2; scanf("%d:%d",&h1,&m1); m1 += h1*60; cin >> name1; scanf("%d:%d",&h2,&m2); m2 += h2*60; cin >> name2; if(i>0 && m1-prv>=t){ name.push_back(name1); stay.push_back(m1-prv); } prv = m2; } cout << name.size() << endl; for(int i=0;i<name.size();i++){ cout << name[i] << " " << stay[i] << endl; } } ```
#include <iostream> #include <vector> #include <algorithm> #include <utility> #include <map> #include <queue> #include <stack> #include <string> #include <sstream> #include <cstring> #include <cstdlib> using namespace std; #define ALL(c) c.begin(),c.end() #define RALL(c) c.rbegin(),c.rend() #define REP(type,i,n) for(type i=0;i<(n);++i) #define MP(a,b) make_pair((a),(b)) #define F_ first #define S_ second typedef long long int lli; typedef pair<int,int> Pi; const int INF=100000000; const long long int INF_=1000000000000000000; int CharToInt(char ch){ return 'a'-ch; } int convert(string s1,string s2){ int a,b; a=60*10*CharToInt(s1[0])+60*CharToInt(s1[1])+CharToInt(s1[3])*10+CharToInt(s1[4]); b=60*10*CharToInt(s2[0])+60*CharToInt(s2[1])+CharToInt(s2[3])*10+CharToInt(s2[4]); return b-a; } int main(){ int N,T; cin >> N >> T; int count=0; vector<pair<string,int> > ans; string time[4],name[4]; REP(int,i,N){ int idx1=i%2==0?0:2; cin >> time[idx1] >> name[idx1] >> time[idx1+1] >> name[idx1+1]; if(i==0) continue; int idx2=i%2==0?3:1; if(convert(time[idx1],time[idx2])>=T){ ++count; ans.push_back(pair<string,int>(name[idx1],convert(time[idx1],time[idx2]))); } } cout << count << endl; REP(int,i,ans.size()){ cout << ans[i].F_ << ' ' << ans[i].S_ << endl; } return 0; }
### Prompt Your challenge is to write a cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <vector> #include <algorithm> #include <utility> #include <map> #include <queue> #include <stack> #include <string> #include <sstream> #include <cstring> #include <cstdlib> using namespace std; #define ALL(c) c.begin(),c.end() #define RALL(c) c.rbegin(),c.rend() #define REP(type,i,n) for(type i=0;i<(n);++i) #define MP(a,b) make_pair((a),(b)) #define F_ first #define S_ second typedef long long int lli; typedef pair<int,int> Pi; const int INF=100000000; const long long int INF_=1000000000000000000; int CharToInt(char ch){ return 'a'-ch; } int convert(string s1,string s2){ int a,b; a=60*10*CharToInt(s1[0])+60*CharToInt(s1[1])+CharToInt(s1[3])*10+CharToInt(s1[4]); b=60*10*CharToInt(s2[0])+60*CharToInt(s2[1])+CharToInt(s2[3])*10+CharToInt(s2[4]); return b-a; } int main(){ int N,T; cin >> N >> T; int count=0; vector<pair<string,int> > ans; string time[4],name[4]; REP(int,i,N){ int idx1=i%2==0?0:2; cin >> time[idx1] >> name[idx1] >> time[idx1+1] >> name[idx1+1]; if(i==0) continue; int idx2=i%2==0?3:1; if(convert(time[idx1],time[idx2])>=T){ ++count; ans.push_back(pair<string,int>(name[idx1],convert(time[idx1],time[idx2]))); } } cout << count << endl; REP(int,i,ans.size()){ cout << ans[i].F_ << ' ' << ans[i].S_ << endl; } return 0; } ```
#include <stdio.h> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <vector> typedef long long int ll; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000001 using namespace std; struct Info{ int time; char name[51]; }; int calc(char time[6]){ return 60*(10*(time[0]-'0')+time[1]-'0') + 10*(time[3] - '0') + time[4] - '0'; } void strcpy(char* to,char* str){ for(int i=0;str[i] != '\0';i++){ to[i] = str[i]; to[i+1] = '\0'; } } int main(){ int N,T,pre = -1,index,tmp,count = 0; char from_station[51],to_station[51],to,start[6],arrive[6]; queue<Info> Q; scanf("%d %d",&N,&T); for(int i = 0; i < N; i++){ scanf("%s %s %s %s",start,from_station,arrive,to_station); if(i > 0){ if((tmp = calc(start)-pre) >= T){ count++; Info info; strcpy(info.name,from_station); info.time = tmp; Q.push(info); } } pre = calc(arrive); } printf("%d\n",count); while(!Q.empty()){ printf("%s %d\n",Q.front().name,Q.front().time); Q.pop(); } return 0; }
### Prompt Generate a cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <stdio.h> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <vector> typedef long long int ll; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000001 using namespace std; struct Info{ int time; char name[51]; }; int calc(char time[6]){ return 60*(10*(time[0]-'0')+time[1]-'0') + 10*(time[3] - '0') + time[4] - '0'; } void strcpy(char* to,char* str){ for(int i=0;str[i] != '\0';i++){ to[i] = str[i]; to[i+1] = '\0'; } } int main(){ int N,T,pre = -1,index,tmp,count = 0; char from_station[51],to_station[51],to,start[6],arrive[6]; queue<Info> Q; scanf("%d %d",&N,&T); for(int i = 0; i < N; i++){ scanf("%s %s %s %s",start,from_station,arrive,to_station); if(i > 0){ if((tmp = calc(start)-pre) >= T){ count++; Info info; strcpy(info.name,from_station); info.time = tmp; Q.push(info); } } pre = calc(arrive); } printf("%d\n",count); while(!Q.empty()){ printf("%s %d\n",Q.front().name,Q.front().time); Q.pop(); } return 0; } ```
#include <iostream> #include <vector> #include <string> #include <cstdio> #include <utility> using namespace std; int main(){ int N, T; cin >> N >> T; int tmp_ar_time_h = -1, tmp_ar_time_m = -1; vector<pair<string, int> > ans; for (int i = 0; i < N; i++) { int st_time_h, st_time_m; int ar_time_h, ar_time_m; string st_name, ar_name; scanf("%d:%d", &st_time_h, &st_time_m); cin >> st_name; scanf("%d:%d", &ar_time_h, &ar_time_m); cin >> ar_name; // cout << st_time << st_name << ar_time << ar_name << endl; if (tmp_ar_time_h == -1 || tmp_ar_time_m == -1) { tmp_ar_time_h = ar_time_h; tmp_ar_time_m = ar_time_m; continue; } int dh = st_time_h - tmp_ar_time_h; int dm = st_time_m - tmp_ar_time_m; int d = 60*dh + dm; if (d >= T) { ans.push_back(make_pair(st_name, d)); } tmp_ar_time_h = ar_time_h; tmp_ar_time_m = ar_time_m; } cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { cout << ans[i].first << " " << ans[i].second << endl; } return 0; }
### Prompt Please formulate a Cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <vector> #include <string> #include <cstdio> #include <utility> using namespace std; int main(){ int N, T; cin >> N >> T; int tmp_ar_time_h = -1, tmp_ar_time_m = -1; vector<pair<string, int> > ans; for (int i = 0; i < N; i++) { int st_time_h, st_time_m; int ar_time_h, ar_time_m; string st_name, ar_name; scanf("%d:%d", &st_time_h, &st_time_m); cin >> st_name; scanf("%d:%d", &ar_time_h, &ar_time_m); cin >> ar_name; // cout << st_time << st_name << ar_time << ar_name << endl; if (tmp_ar_time_h == -1 || tmp_ar_time_m == -1) { tmp_ar_time_h = ar_time_h; tmp_ar_time_m = ar_time_m; continue; } int dh = st_time_h - tmp_ar_time_h; int dm = st_time_m - tmp_ar_time_m; int d = 60*dh + dm; if (d >= T) { ans.push_back(make_pair(st_name, d)); } tmp_ar_time_h = ar_time_h; tmp_ar_time_m = ar_time_m; } cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { cout << ans[i].first << " " << ans[i].second << endl; } return 0; } ```
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Station { string name; int time; Station() {} Station(string name, int time) : name(name), time(time) {} }; int main() { int N, T; char a[55], b[55]; int h1, d1, h2, d2; string s; vector<Station> st; cin >> N >> T; cin >> s >> s; for (int i = 0; i < N - 1; ++i) { scanf("%d:%d %s %d:%d %s", &h1, &d1, a, &h2, &d2, b); int time = (h2 * 60 + d2) - (h1 * 60 + d1); if (time >= T) st.push_back(Station(a, time)); } cin >> s >> s; cout << st.size() << "\n"; for (size_t i = 0; i < st.size(); ++i) cout << st[i].name << " " << st[i].time << "\n"; return 0; }
### Prompt Generate a cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <vector> #include <algorithm> using namespace std; struct Station { string name; int time; Station() {} Station(string name, int time) : name(name), time(time) {} }; int main() { int N, T; char a[55], b[55]; int h1, d1, h2, d2; string s; vector<Station> st; cin >> N >> T; cin >> s >> s; for (int i = 0; i < N - 1; ++i) { scanf("%d:%d %s %d:%d %s", &h1, &d1, a, &h2, &d2, b); int time = (h2 * 60 + d2) - (h1 * 60 + d1); if (time >= T) st.push_back(Station(a, time)); } cin >> s >> s; cout << st.size() << "\n"; for (size_t i = 0; i < st.size(); ++i) cout << st[i].name << " " << st[i].time << "\n"; return 0; } ```
#include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <fstream> #include <functional> #include <bitset> using namespace std; #define int long long int const int INF = 1001001001001001LL; const int MOD = 1000000007; signed main(){ int n, t; cin >> n >> t; vector<pair<string, string> > a(n); vector<pair<string, string> > b(n); for(int i = 0; i < n; i++){ string o, p, q, r; cin >> o >> p >> q >> r; a[i].first = o; a[i].second = p; b[i].first = q; b[i].second = r; } vector<pair<string, int> > ans; for(int i = 0; i < n - 1; i++){ int g = stoi(a[i + 1].first.substr(0, 2)) * 60 + stoi(a[i + 1].first.substr(3, 2)); int s = stoi(b[i].first.substr(0, 2)) * 60 + stoi(b[i].first.substr(3, 2)); if(g - s >= t) ans.push_back({a[i + 1].second, g - s}); } cout << ans.size() << endl; for(int i = 0; i < ans.size(); i++){ cout << ans[i].first << " " << ans[i].second << endl; } return 0; }
### Prompt Your task is to create a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <fstream> #include <functional> #include <bitset> using namespace std; #define int long long int const int INF = 1001001001001001LL; const int MOD = 1000000007; signed main(){ int n, t; cin >> n >> t; vector<pair<string, string> > a(n); vector<pair<string, string> > b(n); for(int i = 0; i < n; i++){ string o, p, q, r; cin >> o >> p >> q >> r; a[i].first = o; a[i].second = p; b[i].first = q; b[i].second = r; } vector<pair<string, int> > ans; for(int i = 0; i < n - 1; i++){ int g = stoi(a[i + 1].first.substr(0, 2)) * 60 + stoi(a[i + 1].first.substr(3, 2)); int s = stoi(b[i].first.substr(0, 2)) * 60 + stoi(b[i].first.substr(3, 2)); if(g - s >= t) ans.push_back({a[i + 1].second, g - s}); } cout << ans.size() << endl; for(int i = 0; i < ans.size(); i++){ cout << ans[i].first << " " << ans[i].second << endl; } return 0; } ```
#include<iostream> #include<vector> #include<utility> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) using namespace std; int tm(string s){ long long res=((s[0]-'0')*10+(s[1]-'0'))*60+(s[3]-'0')*10+(s[4]-'0'); return res; } int main(){ long long n,t; cin>>n>>t; string st[n]; string ar[n]; string stn[n]; string arn[n]; vector<pair<string,long long> > vec; rep(i,n){ cin>>stn[i]>>st[i]>>arn[i]>>ar[i]; } rep(i,n-1){ if(tm(stn[i+1])-tm(arn[i])>=t){ pair<string,int> pr; pr.first=ar[i]; pr.second=tm(stn[i+1])-tm(arn[i]); vec.push_back(pr); } } cout<<vec.size()<<endl; rep(i,vec.size()){ pair<string,int> ans=vec[i]; cout<<ans.first<<" "<<ans.second<<endl; } return 0; }
### Prompt Generate a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<vector> #include<utility> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) using namespace std; int tm(string s){ long long res=((s[0]-'0')*10+(s[1]-'0'))*60+(s[3]-'0')*10+(s[4]-'0'); return res; } int main(){ long long n,t; cin>>n>>t; string st[n]; string ar[n]; string stn[n]; string arn[n]; vector<pair<string,long long> > vec; rep(i,n){ cin>>stn[i]>>st[i]>>arn[i]>>ar[i]; } rep(i,n-1){ if(tm(stn[i+1])-tm(arn[i])>=t){ pair<string,int> pr; pr.first=ar[i]; pr.second=tm(stn[i+1])-tm(arn[i]); vec.push_back(pr); } } cout<<vec.size()<<endl; rep(i,vec.size()){ pair<string,int> ans=vec[i]; cout<<ans.first<<" "<<ans.second<<endl; } return 0; } ```
#include<iostream> #include<algorithm> #include<string> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) using namespace std; int main(){ int n,t; cin>>n>>t; string name1,name2; string canstop[20]; int stoptime[20]; char c; int h,m,ah,am; int cnt=0; cin>>h>>c>>m>>name1; rep(i,n-1){ cin>> h>>c>> m>>name1; cin>>ah>>c>>am>>name2; if(ah*60-h*60+am-m>=t){ stoptime[cnt]=ah*60-h*60+am-m; canstop[cnt++]=name1; } } cin>>h>>c>>m>>name1; cout<<cnt<<endl; rep(i,cnt){ cout<<canstop[i]<<" "<<stoptime[i]<<endl; } }
### Prompt Generate a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<algorithm> #include<string> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) using namespace std; int main(){ int n,t; cin>>n>>t; string name1,name2; string canstop[20]; int stoptime[20]; char c; int h,m,ah,am; int cnt=0; cin>>h>>c>>m>>name1; rep(i,n-1){ cin>> h>>c>> m>>name1; cin>>ah>>c>>am>>name2; if(ah*60-h*60+am-m>=t){ stoptime[cnt]=ah*60-h*60+am-m; canstop[cnt++]=name1; } } cin>>h>>c>>m>>name1; cout<<cnt<<endl; rep(i,cnt){ cout<<canstop[i]<<" "<<stoptime[i]<<endl; } } ```
#include <iostream> #include <cstdio> using namespace std; #define MAX 11 int main(){ int n,t; int a[MAX],b[MAX],c[MAX],d[MAX]; char s[MAX][100],tmp[MAX][100]; char hoge[MAX][100]; scanf("%d %d",&n,&t); for(int i=0; i<n; i++){ scanf("%d:%d %s %d:%d %s",&a[i],&b[i],s[i],&c[i],&d[i],tmp[i]); } int ans=0; for(int i=0; i<n-1; i++){ if( (a[i+1]*60+b[i+1]) - (c[i]*60 + d[i]) >= t) ans++; } cout << ans << endl; for(int i=0; i<n-1; i++){ int x = (a[i+1]*60+b[i+1]) - (c[i]*60+d[i]); if( x >= t ) printf("%s %d\n",s[i+1],x); } }
### Prompt Please create a solution in cpp to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <cstdio> using namespace std; #define MAX 11 int main(){ int n,t; int a[MAX],b[MAX],c[MAX],d[MAX]; char s[MAX][100],tmp[MAX][100]; char hoge[MAX][100]; scanf("%d %d",&n,&t); for(int i=0; i<n; i++){ scanf("%d:%d %s %d:%d %s",&a[i],&b[i],s[i],&c[i],&d[i],tmp[i]); } int ans=0; for(int i=0; i<n-1; i++){ if( (a[i+1]*60+b[i+1]) - (c[i]*60 + d[i]) >= t) ans++; } cout << ans << endl; for(int i=0; i<n-1; i++){ int x = (a[i+1]*60+b[i+1]) - (c[i]*60+d[i]); if( x >= t ) printf("%s %d\n",s[i+1],x); } } ```
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; vector <string> ans; vector <int> num; int pre=1e9; for(int i=0;i<n;i++){ string a,b; int h1,m1,h2,m2; scanf("%d:%d",&h1,&m1); cin>>a; scanf("%d:%d",&h2,&m2); cin>>b; int res=h1*60+m1-(pre); if(res>=m) ans.push_back(a),num.push_back(res); pre=h2*60+m2; } cout <<ans.size()<<endl; for(int i=0;i<ans.size();i++) cout <<ans[i]<<" "<<num[i]<<endl; return 0; }
### Prompt Please create a solution in CPP to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; vector <string> ans; vector <int> num; int pre=1e9; for(int i=0;i<n;i++){ string a,b; int h1,m1,h2,m2; scanf("%d:%d",&h1,&m1); cin>>a; scanf("%d:%d",&h2,&m2); cin>>b; int res=h1*60+m1-(pre); if(res>=m) ans.push_back(a),num.push_back(res); pre=h2*60+m2; } cout <<ans.size()<<endl; for(int i=0;i<ans.size();i++) cout <<ans[i]<<" "<<num[i]<<endl; return 0; } ```
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<math.h> #include<string> #include<string.h> #include<stack> #include<queue> #include<vector> #include<utility> #include<set> #include<map> #include<stdlib.h> #include<iomanip> using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define MOD 1000000007 #define rep(i,n) for(i=0;i<n;i++) #define loop(i,a,n) for(i=a;i<n;i++) #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) typedef vector<int> vi; typedef pair<int,int> pii; int main(void) { int i,j; int n,t; cin>>n>>t; vector<string> name(n); vi ans; vi t1(n,0),t2(n,0); rep(i,n){ string s1,s2,s3,s4; cin>>s1>>s2>>s3>>s4; name[i]=s4; t1[i]=(s1[0]*10+s1[1])*60+s1[3]*10+s1[4]; t2[i]=(s3[0]*10+s3[1])*60+s3[3]*10+s3[4]; } rep(i,n-1) if(t1[i+1]-t2[i]>=t)ans.push_back(i); cout<<ans.size()<<endl; rep(i,ans.size()) cout<<name[ans[i]]<<" "<<t1[ans[i]+1]-t2[ans[i]]<<endl; }
### Prompt Please provide a cpp coded solution to the problem described below: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<math.h> #include<string> #include<string.h> #include<stack> #include<queue> #include<vector> #include<utility> #include<set> #include<map> #include<stdlib.h> #include<iomanip> using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define MOD 1000000007 #define rep(i,n) for(i=0;i<n;i++) #define loop(i,a,n) for(i=a;i<n;i++) #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) typedef vector<int> vi; typedef pair<int,int> pii; int main(void) { int i,j; int n,t; cin>>n>>t; vector<string> name(n); vi ans; vi t1(n,0),t2(n,0); rep(i,n){ string s1,s2,s3,s4; cin>>s1>>s2>>s3>>s4; name[i]=s4; t1[i]=(s1[0]*10+s1[1])*60+s1[3]*10+s1[4]; t2[i]=(s3[0]*10+s3[1])*60+s3[3]*10+s3[4]; } rep(i,n-1) if(t1[i+1]-t2[i]>=t)ans.push_back(i); cout<<ans.size()<<endl; rep(i,ans.size()) cout<<name[ans[i]]<<" "<<t1[ans[i]+1]-t2[ans[i]]<<endl; } ```
#include<iostream> #include<vector> #include<algorithm> #include<string> using namespace std; typedef pair<string,int> P; int main(void){ int n,t; cin >> n >> t; char ch; vector<string>a(n),b(n); vector<int>ha(n),hb(n),ma(n),mb(n); for(int i=0;i<n;i++){ cin >> ha[i] >> ch >> ma[i] >> a[i]; cin >> hb[i] >> ch >> mb[i] >> b[i]; } vector<P>ans; for(int i=0;i<n-1;i++){ int time=(ha[i+1]*60+ma[i+1])-(hb[i]*60+mb[i]); if(time>=t)ans.push_back(P(b[i],time)); } cout << ans.size() << endl; for(int i=0;i<ans.size();i++) cout << ans[i].first << " " << ans[i].second << endl; return 0; }
### Prompt Generate a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<vector> #include<algorithm> #include<string> using namespace std; typedef pair<string,int> P; int main(void){ int n,t; cin >> n >> t; char ch; vector<string>a(n),b(n); vector<int>ha(n),hb(n),ma(n),mb(n); for(int i=0;i<n;i++){ cin >> ha[i] >> ch >> ma[i] >> a[i]; cin >> hb[i] >> ch >> mb[i] >> b[i]; } vector<P>ans; for(int i=0;i<n-1;i++){ int time=(ha[i+1]*60+ma[i+1])-(hb[i]*60+mb[i]); if(time>=t)ans.push_back(P(b[i],time)); } cout << ans.size() << endl; for(int i=0;i<ans.size();i++) cout << ans[i].first << " " << ans[i].second << endl; return 0; } ```
#include <cstdio> #include <iostream> #include <string> using namespace std; int main(){ int n, t, m=0; int st[10], ar[10]; string ans[10]; int anst[10]; scanf(" %d %d", &n, &t); for(int i=0; i<n; ++i){ int a, b, c, d; string p, q; scanf(" %d:%d", &a, &b); cin >> p; scanf(" %d:%d", &c, &d); cin >> q; st[i]=a*60+b; ar[i]=c*60+d; //printf("st[%d]=%d, ar[%d]=%d\n", i, st[i], i, ar[i]); if(i==0) continue; else{ int tt=st[i]-ar[i-1]; if(tt>=t){ ans[m]=p; anst[m]=tt; m++; } } } printf("%d\n", m); for(int i=0; i<m; ++i) cout << ans[i] << " " << anst[i] << endl; }
### Prompt Create a solution in cpp for the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <cstdio> #include <iostream> #include <string> using namespace std; int main(){ int n, t, m=0; int st[10], ar[10]; string ans[10]; int anst[10]; scanf(" %d %d", &n, &t); for(int i=0; i<n; ++i){ int a, b, c, d; string p, q; scanf(" %d:%d", &a, &b); cin >> p; scanf(" %d:%d", &c, &d); cin >> q; st[i]=a*60+b; ar[i]=c*60+d; //printf("st[%d]=%d, ar[%d]=%d\n", i, st[i], i, ar[i]); if(i==0) continue; else{ int tt=st[i]-ar[i-1]; if(tt>=t){ ans[m]=p; anst[m]=tt; m++; } } } printf("%d\n", m); for(int i=0; i<m; ++i) cout << ans[i] << " " << anst[i] << endl; } ```
#include <iostream> #include <string> #include <vector> using namespace std; class Time { public: Time(int hour, int min); public: // return min int operator-(const Time& right) const; private: int m_hour; int m_min; }; inline Time::Time(int hour, int min) : m_hour(hour), m_min(min) { } int Time::operator-(const Time& right) const { int hour_diff = this->m_hour - right.m_hour; int min_diff = this->m_min - right.m_min; return hour_diff * 60 + min_diff; } struct Station { Time time; string name; }; struct Result { int time; string name; }; int main(void) { int station_num, stay_min; cin >> station_num >> stay_min; Station arrival_sta = { Time(0, 0) , "" }; Station leave_sta = { Time(0, 0) , "" }; vector<Result> result; int h, m; char buf_ch; string buf_str; cin >> h >> buf_ch >> m >> buf_str; while (true) { cin >> h >> buf_ch >> m >> arrival_sta.name; arrival_sta.time = Time(h, m); cin >> h >> buf_ch >> m >> leave_sta.name; if (cin.eof() ) break; leave_sta.time = Time(h, m); int t; if ( (t = leave_sta.time - arrival_sta.time) >= stay_min) { result.push_back( {t, leave_sta.name} ); } } cout << result.size() << endl; for (auto r : result) { cout << r.name << " " << r.time << endl; } return 0; }
### Prompt Your task is to create a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <string> #include <vector> using namespace std; class Time { public: Time(int hour, int min); public: // return min int operator-(const Time& right) const; private: int m_hour; int m_min; }; inline Time::Time(int hour, int min) : m_hour(hour), m_min(min) { } int Time::operator-(const Time& right) const { int hour_diff = this->m_hour - right.m_hour; int min_diff = this->m_min - right.m_min; return hour_diff * 60 + min_diff; } struct Station { Time time; string name; }; struct Result { int time; string name; }; int main(void) { int station_num, stay_min; cin >> station_num >> stay_min; Station arrival_sta = { Time(0, 0) , "" }; Station leave_sta = { Time(0, 0) , "" }; vector<Result> result; int h, m; char buf_ch; string buf_str; cin >> h >> buf_ch >> m >> buf_str; while (true) { cin >> h >> buf_ch >> m >> arrival_sta.name; arrival_sta.time = Time(h, m); cin >> h >> buf_ch >> m >> leave_sta.name; if (cin.eof() ) break; leave_sta.time = Time(h, m); int t; if ( (t = leave_sta.time - arrival_sta.time) >= stay_min) { result.push_back( {t, leave_sta.name} ); } } cout << result.size() << endl; for (auto r : result) { cout << r.name << " " << r.time << endl; } return 0; } ```
// clang-format off #include <bits/stdc++.h> #define int long long #define main signed main() #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define forever for (;;) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define prec(n) fixed << setprecision(n) template<typename A> using V = std::vector<A>; template<typename A> using F = std::function<A>; template<typename A, typename B> using P = std::pair<A, B>; using pii = P<int, int>; using vi = V<int>; using vd = V<double>; using vs = V<std::string>; using vpii = V<pii>; using vvi = V<vi>; using vvpii = V<vpii>; constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979; template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } constexpr bool odd(const int n) { return n & 1; } constexpr bool even(const int n) { return ~n & 1; } template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; } template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; } using namespace std; // clang-format on std::vector<std::string> split(const std::string &s, const std::string &delim) { using string = std::string; std::vector<string> v; string::size_type pos = 0; while (pos != string::npos) { string::size_type p = s.find(delim, pos); if (p == string::npos) { v.push_back(s.substr(pos)); break; } v.push_back(s.substr(pos, p - pos)); pos = p + delim.size(); } return v; } main { int n, t; cin >> n >> t; V<P<string, int>> out; V<tuple<int, string, int>> v(n); rep(i, n) { string a, b, c, d; cin >> a >> b >> c >> d; vs v1 = split(a, ":"), v2 = split(c, ":"); v[i] = make_tuple(stoi(v1[0]) * 60 + stoi(v1[1]), b, stoi(v2[0]) * 60 + stoi(v2[1])); } loop(i, 1, n) { int d = get<0>(v[i]) - get<2>(v[i - 1]); if (d >= t) out.emplace_back(get<1>(v[i]), d); } cout << out.size() << endl; for (auto &p : out) cout << p.first << ' ' << p.second << endl; }
### Prompt Your challenge is to write a cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp // clang-format off #include <bits/stdc++.h> #define int long long #define main signed main() #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define forever for (;;) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define prec(n) fixed << setprecision(n) template<typename A> using V = std::vector<A>; template<typename A> using F = std::function<A>; template<typename A, typename B> using P = std::pair<A, B>; using pii = P<int, int>; using vi = V<int>; using vd = V<double>; using vs = V<std::string>; using vpii = V<pii>; using vvi = V<vi>; using vvpii = V<vpii>; constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979; template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } constexpr bool odd(const int n) { return n & 1; } constexpr bool even(const int n) { return ~n & 1; } template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; } template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; } using namespace std; // clang-format on std::vector<std::string> split(const std::string &s, const std::string &delim) { using string = std::string; std::vector<string> v; string::size_type pos = 0; while (pos != string::npos) { string::size_type p = s.find(delim, pos); if (p == string::npos) { v.push_back(s.substr(pos)); break; } v.push_back(s.substr(pos, p - pos)); pos = p + delim.size(); } return v; } main { int n, t; cin >> n >> t; V<P<string, int>> out; V<tuple<int, string, int>> v(n); rep(i, n) { string a, b, c, d; cin >> a >> b >> c >> d; vs v1 = split(a, ":"), v2 = split(c, ":"); v[i] = make_tuple(stoi(v1[0]) * 60 + stoi(v1[1]), b, stoi(v2[0]) * 60 + stoi(v2[1])); } loop(i, 1, n) { int d = get<0>(v[i]) - get<2>(v[i - 1]); if (d >= t) out.emplace_back(get<1>(v[i]), d); } cout << out.size() << endl; for (auto &p : out) cout << p.first << ' ' << p.second << endl; } ```
#include <iostream> #include <sstream> #include <vector> #include <string> #include <map> #include <set> #include <algorithm> #include <stack> #include <queue> #include <deque> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #define REP(i,n) for(int i=0; i<(int)(n); ++i) using namespace std; typedef long long ll; const int INF = 1000000000; const int MOD = 1000000007; const double EPS = 1e-8; int main(){ int N, T; cin >> N >> T; string tmp; cin >> tmp >> tmp; vector<pair<string, int>> ans; for(int i = 0; i < N - 1; i++){ int a, b; scanf("%d:%d", &a, &b); int t = a * 60 + b; cin >> tmp; scanf("%d:%d", &a, &b); t = a * 60 + b - t; cin >> tmp; if(t >= T){ ans.push_back(make_pair(tmp, t)); } } cout << ans.size() << endl; for(auto p : ans){ cout << p.first << " " << p.second << endl; } return 0; }
### Prompt Generate a cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <sstream> #include <vector> #include <string> #include <map> #include <set> #include <algorithm> #include <stack> #include <queue> #include <deque> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #define REP(i,n) for(int i=0; i<(int)(n); ++i) using namespace std; typedef long long ll; const int INF = 1000000000; const int MOD = 1000000007; const double EPS = 1e-8; int main(){ int N, T; cin >> N >> T; string tmp; cin >> tmp >> tmp; vector<pair<string, int>> ans; for(int i = 0; i < N - 1; i++){ int a, b; scanf("%d:%d", &a, &b); int t = a * 60 + b; cin >> tmp; scanf("%d:%d", &a, &b); t = a * 60 + b - t; cin >> tmp; if(t >= T){ ans.push_back(make_pair(tmp, t)); } } cout << ans.size() << endl; for(auto p : ans){ cout << p.first << " " << p.second << endl; } return 0; } ```
#include <iostream> #include <vector> #include <string> using namespace std; #define loop(i,a,b) for(int i=(a); i<(int)(b); i++) #define rep(i,b) loop(i,0,b) int h,m; char c; string sta; int main(){ int n,t;cin>>n>>t; cin>>h>>c>>m; cin>>sta; vector<int> ans_t; vector<string> ans_sta; rep(i,n-1){ int lh,lm; int ah,am; cin>>lh>>c>>lm; cin>>sta; cin>>ah>>c>>am; cin>>sta; int dt=60*(ah-lh)+(am-lm); //printf("%s %d:%d %d:%d %d\n",sta.c_str(), lh,lm,ah,am,dt); if(dt>=t) { ans_t.push_back(dt); ans_sta.push_back(sta); } } cout<<ans_t.size()<<endl; rep(i,ans_t.size()){ cout<<ans_sta[i]<<" "<<ans_t[i]<<endl; } }
### Prompt Your challenge is to write a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <vector> #include <string> using namespace std; #define loop(i,a,b) for(int i=(a); i<(int)(b); i++) #define rep(i,b) loop(i,0,b) int h,m; char c; string sta; int main(){ int n,t;cin>>n>>t; cin>>h>>c>>m; cin>>sta; vector<int> ans_t; vector<string> ans_sta; rep(i,n-1){ int lh,lm; int ah,am; cin>>lh>>c>>lm; cin>>sta; cin>>ah>>c>>am; cin>>sta; int dt=60*(ah-lh)+(am-lm); //printf("%s %d:%d %d:%d %d\n",sta.c_str(), lh,lm,ah,am,dt); if(dt>=t) { ans_t.push_back(dt); ans_sta.push_back(sta); } } cout<<ans_t.size()<<endl; rep(i,ans_t.size()){ cout<<ans_sta[i]<<" "<<ans_t[i]<<endl; } } ```
#include<bits/stdc++.h> using namespace std; int main(){ vector<string>tt; vector<int>t; int a,b; cin>>a>>b; string c,d; cin>>c>>d; for(int e=0;e<a-1;e++){ string f,g; cin>>f>>g; int i=(f[0]-48)*600+(f[1]-48)*60+(f[3]-48)*10+(f[4]-48); cin>>f>>g; int j=(f[0]-48)*600+(f[1]-48)*60+(f[3]-48)*10+(f[4]-48); if(j-i>=b){tt.push_back(g);t.push_back(j-i);} } cin>>c>>d; cout<<tt.size()<<endl; for(int x=0;x<t.size();x++){ cout<<tt[x]<<" "<<t[x]<<endl; } }
### Prompt Your task is to create a Cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<bits/stdc++.h> using namespace std; int main(){ vector<string>tt; vector<int>t; int a,b; cin>>a>>b; string c,d; cin>>c>>d; for(int e=0;e<a-1;e++){ string f,g; cin>>f>>g; int i=(f[0]-48)*600+(f[1]-48)*60+(f[3]-48)*10+(f[4]-48); cin>>f>>g; int j=(f[0]-48)*600+(f[1]-48)*60+(f[3]-48)*10+(f[4]-48); if(j-i>=b){tt.push_back(g);t.push_back(j-i);} } cin>>c>>d; cout<<tt.size()<<endl; for(int x=0;x<t.size();x++){ cout<<tt[x]<<" "<<t[x]<<endl; } } ```
#include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloat> #include <functional> using namespace std; int main() { int n, t; cin >> n >> t; vector<string> fromName(n), toName(n); vector<int> fromTime(n), toTime(n); for(int i=0; i<n; ++i){ int h1, h2, m1, m2; char c; cin >> h1 >> c >> m1 >> fromName[i] >> h2 >> c >> m2 >> toName[i]; fromTime[i] = h1 * 60 + m1; toTime[i] = h2 * 60 + m2; } vector<string> retName; vector<int> retTime; for(int i=0; i<n-1; ++i){ int diff = fromTime[i+1] - toTime[i]; if(diff >= t){ retName.push_back(toName[i]); retTime.push_back(diff); } } cout << retName.size() << endl; for(unsigned i=0; i<retName.size(); ++i) cout << retName[i] << ' ' << retTime[i] << endl; return 0; }
### Prompt Generate a Cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloat> #include <functional> using namespace std; int main() { int n, t; cin >> n >> t; vector<string> fromName(n), toName(n); vector<int> fromTime(n), toTime(n); for(int i=0; i<n; ++i){ int h1, h2, m1, m2; char c; cin >> h1 >> c >> m1 >> fromName[i] >> h2 >> c >> m2 >> toName[i]; fromTime[i] = h1 * 60 + m1; toTime[i] = h2 * 60 + m2; } vector<string> retName; vector<int> retTime; for(int i=0; i<n-1; ++i){ int diff = fromTime[i+1] - toTime[i]; if(diff >= t){ retName.push_back(toName[i]); retTime.push_back(diff); } } cout << retName.size() << endl; for(unsigned i=0; i<retName.size(); ++i) cout << retName[i] << ' ' << retTime[i] << endl; return 0; } ```
#include <cstdio> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <functional> #include <string> #include <utility> using namespace std; using ll = long long int; using P = pair<string, int>; char st_name[10][51], ar_name[10][51]; int st_time[10], ar_time[10]; int main() { int N, T; cin >> N >> T; for (int i = 0; i < N; i++) { int h1, m1, h2, m2; scanf("%d:%d %s %d:%d %s", &h1, &m1, st_name[i], &h2, &m2, ar_name[i]); st_time[i] = h1 * 60 + m1; ar_time[i] = h2 * 60 + m2; } vector<P> ans; for (int i = 1; i < N; i++) { if (st_time[i] - ar_time[i - 1] >= T) { ans.emplace_back(st_name[i], st_time[i] - ar_time[i - 1]); } } cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { cout << ans[i].first << " " << ans[i].second << endl; } }
### Prompt Your challenge is to write a CPP solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <cstdio> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <functional> #include <string> #include <utility> using namespace std; using ll = long long int; using P = pair<string, int>; char st_name[10][51], ar_name[10][51]; int st_time[10], ar_time[10]; int main() { int N, T; cin >> N >> T; for (int i = 0; i < N; i++) { int h1, m1, h2, m2; scanf("%d:%d %s %d:%d %s", &h1, &m1, st_name[i], &h2, &m2, ar_name[i]); st_time[i] = h1 * 60 + m1; ar_time[i] = h2 * 60 + m2; } vector<P> ans; for (int i = 1; i < N; i++) { if (st_time[i] - ar_time[i - 1] >= T) { ans.emplace_back(st_name[i], st_time[i] - ar_time[i - 1]); } } cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { cout << ans[i].first << " " << ans[i].second << endl; } } ```
#include<iostream> #include<vector> #include<string> #include<cstdio> #include<algorithm> #include<map> using namespace std; typedef pair<int,string> P; int main(){ int n,t,h1,m1,h2,m2; char s1[51],s2[51]; scanf("%d %d",&n,&t); vector<P> p; string o,o2; cin >> o >> o2; for(int i=0;i<n-1;i++){ scanf("%d:%d %s %d:%d %s",&h1,&m1,s1,&h2,&m2,s2); int minute = (h2*60+m2)-(h1*60+m1); if(t <= minute) p.push_back(P(minute,s1)); } cin >> o >> o2; cout << p.size() << endl; for(int i=0;i<p.size();i++){ cout << p[i].second << " " << p[i].first << endl; } }
### Prompt Construct a CPP code solution to the problem outlined: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<vector> #include<string> #include<cstdio> #include<algorithm> #include<map> using namespace std; typedef pair<int,string> P; int main(){ int n,t,h1,m1,h2,m2; char s1[51],s2[51]; scanf("%d %d",&n,&t); vector<P> p; string o,o2; cin >> o >> o2; for(int i=0;i<n-1;i++){ scanf("%d:%d %s %d:%d %s",&h1,&m1,s1,&h2,&m2,s2); int minute = (h2*60+m2)-(h1*60+m1); if(t <= minute) p.push_back(P(minute,s1)); } cin >> o >> o2; cout << p.size() << endl; for(int i=0;i<p.size();i++){ cout << p[i].second << " " << p[i].first << endl; } } ```
#include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int N, T; int main() { scanf("%d%d", &N, &T); vector<pair<string, int>> result; char st_name[52], ar_name[52]; int st_hh, st_mm, ar_hh, ar_mm; scanf("%02d:%02d %s %02d:%02d %s", &st_hh, &st_mm, st_name, &ar_hh, &ar_mm, ar_name); for (int i = 1; i < N; i++) { int pre = ar_hh * 60 + ar_mm; scanf("%02d:%02d %s %02d:%02d %s", &st_hh, &st_mm, st_name, &ar_hh, &ar_mm, ar_name); int cur = st_hh * 60 + st_mm; if (cur - pre >= T) { result.emplace_back(st_name, cur - pre); } } cout << result.size() << endl; for (auto r : result) { cout << r.first << ' ' << r.second << endl; } return 0; }
### Prompt Generate a cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int N, T; int main() { scanf("%d%d", &N, &T); vector<pair<string, int>> result; char st_name[52], ar_name[52]; int st_hh, st_mm, ar_hh, ar_mm; scanf("%02d:%02d %s %02d:%02d %s", &st_hh, &st_mm, st_name, &ar_hh, &ar_mm, ar_name); for (int i = 1; i < N; i++) { int pre = ar_hh * 60 + ar_mm; scanf("%02d:%02d %s %02d:%02d %s", &st_hh, &st_mm, st_name, &ar_hh, &ar_mm, ar_name); int cur = st_hh * 60 + st_mm; if (cur - pre >= T) { result.emplace_back(st_name, cur - pre); } } cout << result.size() << endl; for (auto r : result) { cout << r.first << ' ' << r.second << endl; } return 0; } ```
#include <iostream> #include <cstdio> #include <vector> #include <string> using namespace std; typedef pair<int, int> P; class Data { public: string station; P start; P arrival; }; class Ans { public: string station; int time; Ans(string station, int time) : station(station), time(time){} }; void solve() { int N, T; cin >> N >> T; vector<Data> data(N); for (int i = 0; i < N; ++i) { string station2; scanf("%d:%d", &data[i].start.first, &data[i].start.second); cin >> data[i].station; scanf("%d:%d", &data[i].arrival.first, &data[i].arrival.second); cin >> station2; } vector<Ans> ans; for (int i = 0; i < N - 1; ++i) { int startTime = data[i + 1].start.first * 60 + data[i + 1].start.second; int arrivalTime = data[i].arrival.first * 60 + data[i].arrival.second; if (startTime - arrivalTime >= T) { Ans a(data[i+ 1].station, startTime - arrivalTime); ans.push_back(a); } } if (ans.empty()) { cout << 0 << endl; return; } cout << ans.size() << endl; for (int i = 0; i < ans.size(); ++i) { cout << ans[i].station << " " << ans[i].time << endl; } } int main() { solve(); return(0); }
### Prompt Create a solution in CPP for the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <cstdio> #include <vector> #include <string> using namespace std; typedef pair<int, int> P; class Data { public: string station; P start; P arrival; }; class Ans { public: string station; int time; Ans(string station, int time) : station(station), time(time){} }; void solve() { int N, T; cin >> N >> T; vector<Data> data(N); for (int i = 0; i < N; ++i) { string station2; scanf("%d:%d", &data[i].start.first, &data[i].start.second); cin >> data[i].station; scanf("%d:%d", &data[i].arrival.first, &data[i].arrival.second); cin >> station2; } vector<Ans> ans; for (int i = 0; i < N - 1; ++i) { int startTime = data[i + 1].start.first * 60 + data[i + 1].start.second; int arrivalTime = data[i].arrival.first * 60 + data[i].arrival.second; if (startTime - arrivalTime >= T) { Ans a(data[i+ 1].station, startTime - arrivalTime); ans.push_back(a); } } if (ans.empty()) { cout << 0 << endl; return; } cout << ans.size() << endl; for (int i = 0; i < ans.size(); ++i) { cout << ans[i].station << " " << ans[i].time << endl; } } int main() { solve(); return(0); } ```
#include<iostream> using namespace std; int main(){ int n,t,h,m,f=0,ansr[1000]; int ansh=0,ansm=0,anst; int afh,afm; char p; string str[1000],ans[1000],s; cin>>n>>t; cin>>h>>p>>m>>str[0]; for(int i=1;i<n;i++){ cin>>h>>p>>m>>str[i]>>afh>>p>>afm>>s; ansh=afh-h,ansm=afm-m; anst=ansh*60+ansm; if(anst>=t) ans[f]=str[i],ansr[f]=anst,f++; } if(f==0) cout<<"0"<<endl; else{ cout<<f<<endl; for(int i=0;i<f;i++) cout<<ans[i]<<" "<<ansr[i]<<endl; } return 0; }
### Prompt Construct a Cpp code solution to the problem outlined: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> using namespace std; int main(){ int n,t,h,m,f=0,ansr[1000]; int ansh=0,ansm=0,anst; int afh,afm; char p; string str[1000],ans[1000],s; cin>>n>>t; cin>>h>>p>>m>>str[0]; for(int i=1;i<n;i++){ cin>>h>>p>>m>>str[i]>>afh>>p>>afm>>s; ansh=afh-h,ansm=afm-m; anst=ansh*60+ansm; if(anst>=t) ans[f]=str[i],ansr[f]=anst,f++; } if(f==0) cout<<"0"<<endl; else{ cout<<f<<endl; for(int i=0;i<f;i++) cout<<ans[i]<<" "<<ansr[i]<<endl; } return 0; } ```
#include <functional> #include <algorithm> #include <iostream> #include <numeric> #include <iomanip> #include <utility> #include <cstdlib> #include <sstream> #include <bitset> #include <vector> #include <cstdio> #include <ctime> #include <queue> #include <deque> #include <cmath> #include <stack> #include <list> #include <map> #include <set> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define dump(x) cerr << #x << " = " << (x) << endl #define rep(i,n) for(int i=0;i<(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back int solve(string s){ int a=stoi( s.substr(0,2) ); int b=stoi( s.substr(3,2) ); return a*60+b; } int main() { int n,q; cin>>n>>q; string at[20],a[20],bt[20],b[20]; rep(i,n){ cin>>at[i]>>a[i]>>bt[i]>>b[i]; } vector<pair<string,int> > ans; for(int i=1;i<n;i++){ int res=solve(at[i])-solve(bt[i-1]); if(res>=q){ ans.pb(pair<string,int>(a[i],res)); } } cout<<ans.size()<<endl; rep(i,ans.size()){ cout<<ans[i].first<<" "<<ans[i].second<<endl; } return 0; }
### Prompt Create a solution in CPP for the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <functional> #include <algorithm> #include <iostream> #include <numeric> #include <iomanip> #include <utility> #include <cstdlib> #include <sstream> #include <bitset> #include <vector> #include <cstdio> #include <ctime> #include <queue> #include <deque> #include <cmath> #include <stack> #include <list> #include <map> #include <set> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define dump(x) cerr << #x << " = " << (x) << endl #define rep(i,n) for(int i=0;i<(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back int solve(string s){ int a=stoi( s.substr(0,2) ); int b=stoi( s.substr(3,2) ); return a*60+b; } int main() { int n,q; cin>>n>>q; string at[20],a[20],bt[20],b[20]; rep(i,n){ cin>>at[i]>>a[i]>>bt[i]>>b[i]; } vector<pair<string,int> > ans; for(int i=1;i<n;i++){ int res=solve(at[i])-solve(bt[i-1]); if(res>=q){ ans.pb(pair<string,int>(a[i],res)); } } cout<<ans.size()<<endl; rep(i,ans.size()){ cout<<ans[i].first<<" "<<ans[i].second<<endl; } return 0; } ```
#include<iostream> using namespace std; int stot(string s){ int h=0,m=0; h = (s[0]-'0')*10 + s[1]-'0'; m = (s[3]-'0')*10 + s[4]-'0'; return h*60 + m; } int main(){ int n,t; string d[10],a[10]; string name[11]; cin >> n >> t; for(int i=0;i<n;i++){ cin >> d[i] >> name[i] >> a[i] >> name[i+1]; } int cnt = 0; for(int i=1;i<=n;i++){ int len = stot(d[i]) - stot(a[i-1]); if(len>=t)cnt++; } cout << cnt << endl; for(int i=1;i<=n;i++){ int len = stot(d[i]) - stot(a[i-1]); if(len>=t)cout << name[i] << " " << len << endl; } }
### Prompt Construct a CPP code solution to the problem outlined: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> using namespace std; int stot(string s){ int h=0,m=0; h = (s[0]-'0')*10 + s[1]-'0'; m = (s[3]-'0')*10 + s[4]-'0'; return h*60 + m; } int main(){ int n,t; string d[10],a[10]; string name[11]; cin >> n >> t; for(int i=0;i<n;i++){ cin >> d[i] >> name[i] >> a[i] >> name[i+1]; } int cnt = 0; for(int i=1;i<=n;i++){ int len = stot(d[i]) - stot(a[i-1]); if(len>=t)cnt++; } cout << cnt << endl; for(int i=1;i<=n;i++){ int len = stot(d[i]) - stot(a[i-1]); if(len>=t)cout << name[i] << " " << len << endl; } } ```
#include <iostream> #include <vector> using namespace std; int toMin(string s){ int h = (s[0] - '0') * 10 + (s[1] - '0'); int m = (s[3] - '0') * 10 + (s[4] - '0'); return h * 60 + m; } int n, m; int f_tm[12], t_tm[12]; string f_nm[12], t_nm[12]; int main(){ while(cin >> n >> m){ string s; for(int i = 0; i < n; i++){ cin >> s >> f_nm[i]; f_tm[i] = toMin(s); cin >> s >> t_nm[i]; t_tm[i] = toMin(s); } vector<string> nm; vector<int> tm; for(int i = 1; i < n; i++){ if(f_tm[i] - t_tm[i - 1] >= m){ nm.push_back(f_nm[i]); tm.push_back(f_tm[i] - t_tm[i - 1]); } } cout << nm.size() << endl; for(int i = 0; i < nm.size(); i++){ cout << nm[i] << " " << tm[i] << endl; } } }
### Prompt Develop a solution in cpp to the problem described below: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <vector> using namespace std; int toMin(string s){ int h = (s[0] - '0') * 10 + (s[1] - '0'); int m = (s[3] - '0') * 10 + (s[4] - '0'); return h * 60 + m; } int n, m; int f_tm[12], t_tm[12]; string f_nm[12], t_nm[12]; int main(){ while(cin >> n >> m){ string s; for(int i = 0; i < n; i++){ cin >> s >> f_nm[i]; f_tm[i] = toMin(s); cin >> s >> t_nm[i]; t_tm[i] = toMin(s); } vector<string> nm; vector<int> tm; for(int i = 1; i < n; i++){ if(f_tm[i] - t_tm[i - 1] >= m){ nm.push_back(f_nm[i]); tm.push_back(f_tm[i] - t_tm[i - 1]); } } cout << nm.size() << endl; for(int i = 0; i < nm.size(); i++){ cout << nm[i] << " " << tm[i] << endl; } } } ```
#include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(),(c).end() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++) #define iter(c) __typeof((c).begin()) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) #define pb(a) push_back(a) #define pr(a) cout<<(a)<<endl #define PR(a,b) cout<<(a)<<" "<<(b)<<endl #define F first #define S second #define ll long long bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;} const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; typedef pair<string,int> P; int main() { int n,m; cin >> n >> m; int prev=MAX; int a,b,c,d; string s,t; vector<P> v; rep(i,n) { scanf("%d%*c%d",&a,&b); cin >> s; scanf("%d%*c%d",&c,&d); cin >> t; a=a*60+b;c=c*60+d; if(a-prev>=m) v.pb(P(s,a-prev)); prev=c; } pr(v.size()); rep(i,v.size()) PR(v[i].F,v[i].S); return 0; }
### Prompt Please formulate a Cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(),(c).end() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++) #define iter(c) __typeof((c).begin()) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) #define pb(a) push_back(a) #define pr(a) cout<<(a)<<endl #define PR(a,b) cout<<(a)<<" "<<(b)<<endl #define F first #define S second #define ll long long bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;} const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; typedef pair<string,int> P; int main() { int n,m; cin >> n >> m; int prev=MAX; int a,b,c,d; string s,t; vector<P> v; rep(i,n) { scanf("%d%*c%d",&a,&b); cin >> s; scanf("%d%*c%d",&c,&d); cin >> t; a=a*60+b;c=c*60+d; if(a-prev>=m) v.pb(P(s,a-prev)); prev=c; } pr(v.size()); rep(i,v.size()) PR(v[i].F,v[i].S); return 0; } ```
#include <string> #include <iostream> using namespace std; int n, t, x1[15], x2[15]; string s1[15], s2[15], z; int main() { cin >> n >> t; for (int i = 0; i < n; i++) { cin >> z >> s1[i]; x1[i] = stoi(z.substr(0, 2)) * 60 + stoi(z.substr(3, 2)); cin >> z >> s2[i]; x2[i] = stoi(z.substr(0, 2)) * 60 + stoi(z.substr(3, 2)); } int cnt = 0; for (int i = 1; i < n; i++) { if (x1[i] - x2[i - 1] >= t) cnt++; } cout << cnt << endl; for (int i = 1; i < n; i++) { if (x1[i] - x2[i - 1] >= t) cout << s1[i] << ' ' << x1[i] - x2[i - 1] << endl; } return 0; }
### Prompt Please formulate a Cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <string> #include <iostream> using namespace std; int n, t, x1[15], x2[15]; string s1[15], s2[15], z; int main() { cin >> n >> t; for (int i = 0; i < n; i++) { cin >> z >> s1[i]; x1[i] = stoi(z.substr(0, 2)) * 60 + stoi(z.substr(3, 2)); cin >> z >> s2[i]; x2[i] = stoi(z.substr(0, 2)) * 60 + stoi(z.substr(3, 2)); } int cnt = 0; for (int i = 1; i < n; i++) { if (x1[i] - x2[i - 1] >= t) cnt++; } cout << cnt << endl; for (int i = 1; i < n; i++) { if (x1[i] - x2[i - 1] >= t) cout << s1[i] << ' ' << x1[i] - x2[i - 1] << endl; } return 0; } ```
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<set> #include<list> #include<queue> #include<cmath> #include<functional> #include<algorithm> #define INF (1<<29) #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int tominutes(string &s){ int a=0; a+=(s[0]-'0')*60*10; a+=(s[1]-'0')*60; a+=(s[3]-'0')*10; a+=(s[4]-'0'); return a; } int main(){ int n,t; vector<pair<string,int> > v; cin>>n>>t; int a; string s,b; cin>>s>>s>>s; a=tominutes(s); cin>>b; for(int i=1;i<n;i++){ int c; string d; cin>>s>>d; c=tominutes(s); if((c-a)>=t){ v.push_back(make_pair(b,c-a)); } cin>>s>>b; a=tominutes(s); } cout<<v.size()<<endl; for(int i=0;i<v.size();i++){ cout<<v[i].first<<' '<<v[i].second<<endl; } return 0; }
### Prompt Develop a solution in Cpp to the problem described below: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<set> #include<list> #include<queue> #include<cmath> #include<functional> #include<algorithm> #define INF (1<<29) #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int tominutes(string &s){ int a=0; a+=(s[0]-'0')*60*10; a+=(s[1]-'0')*60; a+=(s[3]-'0')*10; a+=(s[4]-'0'); return a; } int main(){ int n,t; vector<pair<string,int> > v; cin>>n>>t; int a; string s,b; cin>>s>>s>>s; a=tominutes(s); cin>>b; for(int i=1;i<n;i++){ int c; string d; cin>>s>>d; c=tominutes(s); if((c-a)>=t){ v.push_back(make_pair(b,c-a)); } cin>>s>>b; a=tominutes(s); } cout<<v.size()<<endl; for(int i=0;i<v.size();i++){ cout<<v[i].first<<' '<<v[i].second<<endl; } return 0; } ```
#include<bits/stdc++.h> #define REP(i,s,n) for(int i=s;i<n;i++) #define rep(i,n) REP(i,0,n) using namespace std; int toTime(string s) { int h,m; stringstream ss; s[2] = ' '; ss << s; ss >> h; ss >> m; return h * 60 + m; } string input[200][4]; int main(){ int n,T; cin >> n >> T; typedef pair<string,int> si; vector<si> vec; rep(i,n) rep(j,4) cin >> input[i][j]; rep(i,n-1){ int time1=toTime(input[i][2]),time2=toTime(input[i+1][0]); if(time2-time1>=T) vec.push_back(si(input[i][3],time2-time1)); } cout << vec.size() << endl; rep(i,vec.size()){ cout << vec[i].first << " " << vec[i].second << endl; } return 0; }
### Prompt Generate a cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<bits/stdc++.h> #define REP(i,s,n) for(int i=s;i<n;i++) #define rep(i,n) REP(i,0,n) using namespace std; int toTime(string s) { int h,m; stringstream ss; s[2] = ' '; ss << s; ss >> h; ss >> m; return h * 60 + m; } string input[200][4]; int main(){ int n,T; cin >> n >> T; typedef pair<string,int> si; vector<si> vec; rep(i,n) rep(j,4) cin >> input[i][j]; rep(i,n-1){ int time1=toTime(input[i][2]),time2=toTime(input[i+1][0]); if(time2-time1>=T) vec.push_back(si(input[i][3],time2-time1)); } cout << vec.size() << endl; rep(i,vec.size()){ cout << vec[i].first << " " << vec[i].second << endl; } return 0; } ```
#include<stdio.h> #include<string.h> int main(){ int a,b; scanf("%d %d",&a,&b); int i,c,d,f,g,j=0; char e[51]={0}; char k[51][180]={0}; int l[180]={0}; scanf("%d:%d %s",&c,&d,e); for(i=0;i<a-1;i++){ scanf("%d:%d %s %d:%d %s",&c,&d,e,&f,&g,e); c*=60; f*=60; if(f+g-c-d>=b){ j++; strcpy(k[j],e); l[j]=f+g-c-d; } } scanf("%d:%d %s",&c,&d,e); printf("%d\n",j); if(j!=0){ for(i=1;i<=j;i++){ printf("%s %d\n",k[i],l[i]); } } }
### Prompt Develop a solution in cpp to the problem described below: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<stdio.h> #include<string.h> int main(){ int a,b; scanf("%d %d",&a,&b); int i,c,d,f,g,j=0; char e[51]={0}; char k[51][180]={0}; int l[180]={0}; scanf("%d:%d %s",&c,&d,e); for(i=0;i<a-1;i++){ scanf("%d:%d %s %d:%d %s",&c,&d,e,&f,&g,e); c*=60; f*=60; if(f+g-c-d>=b){ j++; strcpy(k[j],e); l[j]=f+g-c-d; } } scanf("%d:%d %s",&c,&d,e); printf("%d\n",j); if(j!=0){ for(i=1;i<=j;i++){ printf("%s %d\n",k[i],l[i]); } } } ```
//============================================================================ // Name : aoj2515.cpp // Author : afterCmidday // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <stdio.h> #include <string.h> int translate(char *s){ int h, m; h = (s[0] - '0') * 10 + s[1] - '0'; m = (s[3] - '0') * 10 + s[4] - '0'; return h * 60 + m; } int main() { int i, n, t, cnt = 0; char tm1[5], tm2[5], name[256], ans[500][1000]; scanf("%d %d", &n, &t); scanf("%s", tm1); for (i = 0; i < n - 1; i++){ scanf("%s", name); scanf("%s", tm1); scanf("%s", name); scanf("%s", tm2); int tmp = translate(tm2) - translate(tm1); if (tmp >= t){ sprintf(ans[cnt++], "%s %d", name, tmp); } } printf("%d\n", cnt); for (i = 0; i < cnt; i++){ printf("%s\n", ans[i]); } }
### Prompt In cpp, your task is to solve the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp //============================================================================ // Name : aoj2515.cpp // Author : afterCmidday // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <stdio.h> #include <string.h> int translate(char *s){ int h, m; h = (s[0] - '0') * 10 + s[1] - '0'; m = (s[3] - '0') * 10 + s[4] - '0'; return h * 60 + m; } int main() { int i, n, t, cnt = 0; char tm1[5], tm2[5], name[256], ans[500][1000]; scanf("%d %d", &n, &t); scanf("%s", tm1); for (i = 0; i < n - 1; i++){ scanf("%s", name); scanf("%s", tm1); scanf("%s", name); scanf("%s", tm2); int tmp = translate(tm2) - translate(tm1); if (tmp >= t){ sprintf(ans[cnt++], "%s %d", name, tmp); } } printf("%d\n", cnt); for (i = 0; i < cnt; i++){ printf("%s\n", ans[i]); } } ```
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int readtime(string time){ int h,m; sscanf(time.c_str(),"%02d:%02d",&h,&m); return h*60+m; } int main(){ int n,t;cin>>n>>t; vector<pair<string,int> > ans; string st,sn,at,an; for(int i=0;i<n;++i){ string old_at; if(i){ old_at=at; } cin>>st>>sn>>at>>an; if(readtime(st)-readtime(old_at)>=t){ ans.push_back(make_pair(sn,readtime(st)-readtime(old_at))); } } cout<<ans.size()<<endl; for(int i=0;i<ans.size();++i){ cout<<ans[i].first<<" "<<ans[i].second<<endl; } return 0; }
### Prompt Develop a solution in CPP to the problem described below: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int readtime(string time){ int h,m; sscanf(time.c_str(),"%02d:%02d",&h,&m); return h*60+m; } int main(){ int n,t;cin>>n>>t; vector<pair<string,int> > ans; string st,sn,at,an; for(int i=0;i<n;++i){ string old_at; if(i){ old_at=at; } cin>>st>>sn>>at>>an; if(readtime(st)-readtime(old_at)>=t){ ans.push_back(make_pair(sn,readtime(st)-readtime(old_at))); } } cout<<ans.size()<<endl; for(int i=0;i<ans.size();++i){ cout<<ans[i].first<<" "<<ans[i].second<<endl; } return 0; } ```
#include<iostream> #include<sstream> using namespace std; int main(){ int N,T; cin>>N>>T; int c=0; stringstream ss; int l=99999; while(N--){ int h1,m1,h2,m2; char s1[51],s2[51]; char d1,d2; cin>>h1>>d1>>m1>>s1>>h2>>d2>>m2>>s2; int i=h1*60+m1-l; if(i>=T){ c++; ss<<s1<<' '<<i<<endl; } l=h2*60+m2; } cout<<c<<endl; cout<<ss.str(); }
### Prompt Generate a cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<sstream> using namespace std; int main(){ int N,T; cin>>N>>T; int c=0; stringstream ss; int l=99999; while(N--){ int h1,m1,h2,m2; char s1[51],s2[51]; char d1,d2; cin>>h1>>d1>>m1>>s1>>h2>>d2>>m2>>s2; int i=h1*60+m1-l; if(i>=T){ c++; ss<<s1<<' '<<i<<endl; } l=h2*60+m2; } cout<<c<<endl; cout<<ss.str(); } ```
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<n;i++) using namespace std; int main() { int n, t; scanf("%d%d", &n, &t); int tim; vector<pair<string, int>>ans; rep(i, n) { int h1, m1, h2, m2; string s1, s2; scanf("%d:%d", &h1, &m1); cin >> s1; scanf("%d:%d", &h2, &m2); cin >> s2; int tim1 = h1 * 60 + m1; if (i&&tim1 - tim >= t)ans.push_back({ s1, tim1 - tim }); tim = h2 * 60 + m2; } printf("%d\n", ans.size()); for (auto p : ans)cout << p.first << ' ' << p.second << endl; }
### Prompt Please create a solution in cpp to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<n;i++) using namespace std; int main() { int n, t; scanf("%d%d", &n, &t); int tim; vector<pair<string, int>>ans; rep(i, n) { int h1, m1, h2, m2; string s1, s2; scanf("%d:%d", &h1, &m1); cin >> s1; scanf("%d:%d", &h2, &m2); cin >> s2; int tim1 = h1 * 60 + m1; if (i&&tim1 - tim >= t)ans.push_back({ s1, tim1 - tim }); tim = h2 * 60 + m2; } printf("%d\n", ans.size()); for (auto p : ans)cout << p.first << ' ' << p.second << endl; } ```
#include<bits/stdc++.h> using namespace std; int main(){ int n, t; cin >> n >> t; string s[2][n]; int time[2][n]; for(int j = 0; j < n; j++){ for(int i = 0;i < 2; i++){ int a, b; scanf("%d:%d", &a, &b); time[i][j] = 60*a + b; cin >> s[i][j]; } } int ans = 0; vector<int> id; for(int i = 1; i < n; i++) { if(time[0][i] - time[1][i - 1] >= t){ ans++; id.push_back(i); } } cout << ans << endl; for(int i = 0; i < id.size(); i++) { cout << s[0][id[i]] << " " << time[0][id[i]] - time[1][id[i] - 1] << endl; } return 0; }
### Prompt In cpp, your task is to solve the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<bits/stdc++.h> using namespace std; int main(){ int n, t; cin >> n >> t; string s[2][n]; int time[2][n]; for(int j = 0; j < n; j++){ for(int i = 0;i < 2; i++){ int a, b; scanf("%d:%d", &a, &b); time[i][j] = 60*a + b; cin >> s[i][j]; } } int ans = 0; vector<int> id; for(int i = 1; i < n; i++) { if(time[0][i] - time[1][i - 1] >= t){ ans++; id.push_back(i); } } cout << ans << endl; for(int i = 0; i < id.size(); i++) { cout << s[0][id[i]] << " " << time[0][id[i]] - time[1][id[i] - 1] << endl; } return 0; } ```
#include<iostream> #include<vector> using namespace std; int calc(int h1,int m1,int h2,int m2){ return 60*(h2-h1)+(m2-m1); } int main(){ int n; cin>>n; int t; cin>>t; int sh[n],sm[n],eh[n],em[n]; string s[n+1]; for(int i=0;i<n;i++){ scanf(" %d:%d",&sh[i],&sm[i]); cin>>s[i]; scanf(" %d:%d",&eh[i],&em[i]); cin>>s[i+1]; } vector<pair<string,int>> ans; for(int i=0;i<n-1;++i){ if(calc(eh[i],em[i],sh[i+1],sm[i+1])>=t){ ans.push_back({s[i+1],calc(eh[i],em[i],sh[i+1],sm[i+1])}); } } cout<<ans.size()<<endl; for(auto e : ans){ cout<<e.first<<" "<<e.second<<endl; } }
### Prompt Develop a solution in CPP to the problem described below: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<vector> using namespace std; int calc(int h1,int m1,int h2,int m2){ return 60*(h2-h1)+(m2-m1); } int main(){ int n; cin>>n; int t; cin>>t; int sh[n],sm[n],eh[n],em[n]; string s[n+1]; for(int i=0;i<n;i++){ scanf(" %d:%d",&sh[i],&sm[i]); cin>>s[i]; scanf(" %d:%d",&eh[i],&em[i]); cin>>s[i+1]; } vector<pair<string,int>> ans; for(int i=0;i<n-1;++i){ if(calc(eh[i],em[i],sh[i+1],sm[i+1])>=t){ ans.push_back({s[i+1],calc(eh[i],em[i],sh[i+1],sm[i+1])}); } } cout<<ans.size()<<endl; for(auto e : ans){ cout<<e.first<<" "<<e.second<<endl; } } ```
#include<iostream> #include<cstdio> #include<cstdlib> #include<utility> #include<vector> using namespace std; int timeAbs(string t1,string t2); int main(){ vector<pair<string,int> > vec; int ans=0; int n,t; cin>>n>>t; string st_time[n],st_name[n],ar_time[n],ar_name[n]; for(int i=0;i<n;i++) cin>>st_time[i]>>st_name[i]>>ar_time[i]>>ar_name[i]; for(int i=0;i<n-1;i++){ int time; if(timeAbs(ar_time[i],st_time[i+1])>=t){ vec.push_back(make_pair(ar_name[i],timeAbs(ar_time[i],st_time[i+1]))); ans++; } } cout<<ans<<endl; for(int i=0;i<vec.size();i++) cout<<vec[i].first<<" "<<vec[i].second<<endl; return 0; } int timeAbs(string s,string e){ /*return t2 - t1 format: HH:MM */ int s_min,s_hour,e_min,e_hour; int ans; if(s.size()!=5 || e.size()!=5) return -1; s_min=atoi(s.substr(3,2).c_str()); s_hour=atoi(s.substr(0,2).c_str()); e_min=atoi(e.substr(3,2).c_str()); e_hour=atoi(e.substr(0,2).c_str()); ans=(e_hour*60 + e_min)-(s_hour*60 + s_min); return ans; }
### Prompt Please create a solution in CPP to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<iostream> #include<cstdio> #include<cstdlib> #include<utility> #include<vector> using namespace std; int timeAbs(string t1,string t2); int main(){ vector<pair<string,int> > vec; int ans=0; int n,t; cin>>n>>t; string st_time[n],st_name[n],ar_time[n],ar_name[n]; for(int i=0;i<n;i++) cin>>st_time[i]>>st_name[i]>>ar_time[i]>>ar_name[i]; for(int i=0;i<n-1;i++){ int time; if(timeAbs(ar_time[i],st_time[i+1])>=t){ vec.push_back(make_pair(ar_name[i],timeAbs(ar_time[i],st_time[i+1]))); ans++; } } cout<<ans<<endl; for(int i=0;i<vec.size();i++) cout<<vec[i].first<<" "<<vec[i].second<<endl; return 0; } int timeAbs(string s,string e){ /*return t2 - t1 format: HH:MM */ int s_min,s_hour,e_min,e_hour; int ans; if(s.size()!=5 || e.size()!=5) return -1; s_min=atoi(s.substr(3,2).c_str()); s_hour=atoi(s.substr(0,2).c_str()); e_min=atoi(e.substr(3,2).c_str()); e_hour=atoi(e.substr(0,2).c_str()); ans=(e_hour*60 + e_min)-(s_hour*60 + s_min); return ans; } ```
#include<stdio.h> #include<algorithm> using namespace std; char str[20][60]; int ans[20]; int t[20]; int main(){ int a,b;scanf("%d%d",&a,&b); int last=0; int ret=0; for(int i=0;i<a;i++){ int p,q,r,s; scanf("%d:%d%s%d:%d%s",&p,&q,str[i],&r,&s,str[i+1]); p=p*60+q; r=r*60+s; if(i){ if(p-last>=b){ t[ret]=p-last; ans[ret++]=i; } } last=r; } printf("%d\n",ret); for(int i=0;i<ret;i++)printf("%s %d\n",str[ans[i]],t[i]); }
### Prompt Generate a Cpp solution to the following problem: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates freely (detailed usage rules are omitted). The attraction of the 18 Ticket is that you can use your spare time to see local souvenirs at the station where you change trains. She wants to visit various stations during her trip because it is a great opportunity. However, since I don't want to miss the next train, I decided to look around the station only when the time between the time I arrived at the transfer station and the time I left the transfer station was T minutes or more. You will be given a transfer plan using Mr. Takatsuki's 18 ticket, so output the name and time of the station you can look around. Please note that the station that departs first and the station that arrives last are not candidates for exploration. Constraints * 1 <= N <= 10 * 1 <= T <= 180 * st_timei, ar_timei * Represented by "HH: MM", HH is 00 or more and 23 or less, and MM is 00 or more and 59 or less. HH is hours and MM is minutes. * 00:00 <= st_time1 <ar_time1 <st_time2 <ar_time2 <... <st_timeN <ar_timeN <= 23:59 * st_namei, ar_namei * A character string represented by uppercase and lowercase letters. * 1 <= string length <= 50 * The names of the i-th arrival station ar_namei and the i + 1th departure station st_namei + 1 match. * The names of st_name1, ar_nameN, and the transfer station are different character strings. Input Each data set is input in the following format. N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN N is an integer representing the number of times the train is boarded, and T is an integer representing the permissible time (minutes) to see the transfer station. Subsequently, train departure and arrival pairs are given over N lines. The input of each line means that the train that Mr. Takatsuki rides departs from the station of st_namei at the time of st_timei, and that the train that Mr. Takatsuki rides arrives at the station of ar_namei at the time of ar_timei. Output Output in the following format for each data set. M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M (0 <= M <= N -1) is an integer that represents the number of stations you can look around. Then, over M lines, a list of stations that can be visited is output in ascending order of time. Each line means that you can walk around the station of stay_namei for stay_timei minutes. Examples Input N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Output 2 Kanazawa 55 Niitsu 24 Input 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output 2 Kanazawa 55 Niitsu 24 Input 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output 0 ### Response ```cpp #include<stdio.h> #include<algorithm> using namespace std; char str[20][60]; int ans[20]; int t[20]; int main(){ int a,b;scanf("%d%d",&a,&b); int last=0; int ret=0; for(int i=0;i<a;i++){ int p,q,r,s; scanf("%d:%d%s%d:%d%s",&p,&q,str[i],&r,&s,str[i+1]); p=p*60+q; r=r*60+s; if(i){ if(p-last>=b){ t[ret]=p-last; ans[ret++]=i; } } last=r; } printf("%d\n",ret); for(int i=0;i<ret;i++)printf("%s %d\n",str[ans[i]],t[i]); } ```