luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/LC3A #809

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Chi tiết bài tập - Luyện Code Online

https://oj.luyencode.net/problem/LC3A

ThienSimp03 commented 2 years ago

ai có thể cho em xin test case 1 vs test case 2 vs đc ko ạ em cảm ơn

tiendat08092001 commented 2 years ago

test1 vs 2 là gì v mn?

ThuanNqt commented 2 years ago

test 1 và 2 là gì nhỉ sao lại lỗi tle (^_^)

nguyenhungidol commented 2 years ago

Cho em xin cách làm ạ

winPd123 commented 1 year ago

cho em hỏi bài này của em bị sai chỗ nào ạ

include

include

using namespace std; int find(string str1, string str2) { int dem = 0; for (int i = 0; i < str1.length(); i++) for (int j = 0; j < str2.length(); j++) { if (str1[i] == str2[j]) dem++; } if (dem == str1.length()) return 0; else return 1; } int main() { int n; cin >> n; int arr[n], i = 0, n1 = n; string str1, str2; while(n >= 1 && n <= 100) { cin >> str1; cin >> str2; if (find(str1, str2) == 0) { arr[i] = str2.length() - str1.length(); } else { arr[i] = -1; } n--; i++; } for (int k = 0; k < n1; k++) { if (arr[k] != -1) cout << "Case " << k+1 << ":" << arr[k] << endl; else cout << "Case " << k+1 << ": IMPOSSIBLE" << endl; } }

hnimtahn commented 1 year ago

include<bits/stdc++.h>

using namespace std;

int main() { int t; cin>>t; cin.ignore(); for(int z = 1; z <= t; z++) { string s; cin >> s; string p; cin >> p; cout<< "Case #"<< z << ": "; int j = 0; for(int i = 0; i < p.size(); i++) { if(p[i] == s[j]) j++; } if(j == s.size()) cout << p.size() - s.size() << endl; else cout << "IMPOSSIBLE" << endl; } }

102210292githug commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

```cpp #include using namespace std; #define MOD 1000000007 //#define base 31 #define rep(i, n) for(int i = 1; i <= (n); i++) #define fo(i, n) for(int i = 0; i < (n); i++) #define per(i, n) for(int i = (n); i >= 1; i--) #define rfo(i, n) for(int i = (n-1); i >= 0; i--) #define pb push_back #define ff first #define ss second #define vt vector #define all(x) x.begin(),x.end() #define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pli; typedef pair pll; typedef map mii; typedef vt vti; const double Pi = acos(- 1.0); const int N = 1e6+6; const int inf = INT_MAX; templateostream& operator<<(std::ostream& os, const std::vector& vec) {for(T i : vec) os << i << ' '; return os;} void solve(){ string s, a; cin >> s >> a; int n = s.size(), m = a.size(); int ans = 0; ans -= (m < n); int tmp = m-n; for(int i = 0, j = 0; i < n && ans != -1; i++, j++){ if(s[i] != a[j]){ //cout << i << j; while(j < m && a[j] != s[i]) ++ans, tmp--, ++j; if(j == m|| a[j] != s[i] ) ans = -1; } if(i != n-1 && j >= m-1) ans = -1; } if(ans != -1){ cout << ans + tmp << '\n'; } else cout << "IMPOSSIBLE\n"; } int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int t = 1; cin >> t; int x = 1; while(t--) { cout << "Case #" << x++ << ": "; solve(); } return 0; } /* Test: 2 Ilovecoding IIllovecoding KickstartIsFun kkickstartiisfun */ ```