QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#457194#8832. Daily Disinfectionucup-team3699#Compile Error//C++20700b2024-06-29 08:56:532024-06-29 08:56:54

Judging History

你现在查看的是最新测评结果

  • [2024-06-29 08:56:54]
  • 评测
  • [2024-06-29 08:56:53]
  • 提交

answer


using namespace std;
int n;
int cal(string &s){
    int f0;
    for (int i = 0; i < n; i++){
        if(s[i] == '0'){
            f0 = i;
            break;
        }
    }
    int now = f0 + 1, ans = f0;
    f0 = 0;
    for (; now < n; now++){
        if(s[now] == '1')
            ans += now - f0, f0 = now;
        else
            f0 = now;
    }
    return ans;
}
void solve(){
    string s;
    cin >> n >> s;
    int ans = cal(s);
    reverse(s.begin(), s.end());
    ans = min(ans, cal(s));
    cout << ans << "\n";
}
signed main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--)
        solve();
    return 0;
}

详细

answer.code:4:9: error: ‘string’ was not declared in this scope
    4 | int cal(string &s){
      |         ^~~~~~
answer.code:1:1: note: ‘std::string’ is defined in header ‘<string>’; did you forget to ‘#include <string>’?
  +++ |+#include <string>
    1 | 
answer.code:4:17: error: ‘s’ was not declared in this scope
    4 | int cal(string &s){
      |                 ^
answer.code: In function ‘void solve()’:
answer.code:23:5: error: ‘string’ was not declared in this scope
   23 |     string s;
      |     ^~~~~~
answer.code:23:5: note: ‘std::string’ is defined in header ‘<string>’; did you forget to ‘#include <string>’?
answer.code:24:5: error: ‘cin’ was not declared in this scope
   24 |     cin >> n >> s;
      |     ^~~
answer.code:1:1: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
  +++ |+#include <iostream>
    1 | 
answer.code:24:17: error: ‘s’ was not declared in this scope
   24 |     cin >> n >> s;
      |                 ^
answer.code:25:18: error: ‘cal’ cannot be used as a function
   25 |     int ans = cal(s);
      |               ~~~^~~
answer.code:26:5: error: ‘reverse’ was not declared in this scope
   26 |     reverse(s.begin(), s.end());
      |     ^~~~~~~
answer.code:27:23: error: ‘cal’ cannot be used as a function
   27 |     ans = min(ans, cal(s));
      |                    ~~~^~~
answer.code:27:11: error: ‘min’ was not declared in this scope
   27 |     ans = min(ans, cal(s));
      |           ^~~
answer.code:28:5: error: ‘cout’ was not declared in this scope
   28 |     cout << ans << "\n";
      |     ^~~~
answer.code:28:5: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
answer.code: In function ‘int main()’:
answer.code:31:5: error: ‘ios_base’ has not been declared
   31 |     ios_base::sync_with_stdio(0), cin.tie(0);
      |     ^~~~~~~~
answer.code:31:35: error: ‘cin’ was not declared in this scope
   31 |     ios_base::sync_with_stdio(0), cin.tie(0);
      |                                   ^~~
answer.code:31:35: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?