Untitled
unknown
plain_text
a year ago
2.7 kB
6
Indexable
Never
QUEs 1 #include <iostream> using namespace std; int main () { int t; cin >> t; while (t--) { string s; cin >> s; int ans = 0; int digit = s[0] - '0'; if (digit == 0) ans += (10 - 1); else ans += (digit-1); ans++; for (int i=1; i<4; i++) { digit = s[i]-'0'; int prev = s[i-1] - '0'; if (prev==0) prev=10; if (digit==0) { ans += (10 - prev); } else ans += abs(digit-prev); ans++; } cout << ans << '\n'; } return 0; QUes 2 #include <iostream> using namespace std; int main() { int t; cin >> t; while (t--) { int n,k; cin >> n >> k; int arr[26] = {0}; string s; cin >> s; for (char &ch: s) { arr[ch-'a']++; } int odd = 0; for (int &x: arr) { if (x%2==1) odd++; } if ( odd - k <= 1) cout << "YES" << '\n'; else cout << "NO" << '\n'; } } QUES 3 #include <iostream> using namespace std; int main () { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int num; if (k==2) { bool div = false; while (n--) { cin >> num; if (num%2 == 0) div = true; } if (div) cout << 0 << '\n'; else cout << 1 << '\n'; } else if (k==3) { bool rem0=false, rem1=false, rem2=false; while (n--) { cin >> num; if (num%3==0) rem0 = true; else if (num%3==1) rem1 = true; else rem2 = true; } if (rem0) cout << 0 << '\n'; else if (rem2) cout << 1 << '\n'; else cout << 2 << '\n'; } else if (k==4) { int div2=0, div4=0, maxrem=1, nott=0; while (n--) { cin >> num; if (num%4==0) div4 = 1; if (num%2==0) div2++; else nott++; maxrem = max (maxrem, num%4); } if (div4 || div2>=2) cout << 0 << '\n'; else if (maxrem==3 || (div2==1 && nott>=1)) cout << 1 << '\n'; else cout << 2 << '\n'; } else { bool div = false; int maxrem = 0; while (n--) { cin >> num; if (num%5==0) div = true; maxrem = max (maxrem, num%5); } if (div) cout << 0 << '\n'; else cout << 5 - maxrem << '\n'; } } return 0; }