Мое поведение кода C ++ сбивает с толку, что происходит? [закрыто]C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Мое поведение кода C ++ сбивает с толку, что происходит? [закрыто]

Сообщение Anonymous »

Я решил проблему Codeforces (ссылка) и написал для нее код C ++, и он ясно прошел образцы, но я получил WA на примере 2 < /p>
Я проверил учебник и увидел, что я пытаюсь реализовать ту же идею (учебник. Проблема h).

Код: Выделить всё

#include
using namespace std;

int max_32 = 0x80000000,max_31 = 0x40000000,max_30 = 0x20000000;

//i have pretty much done similar to the tutotial soution for this problem
//slight different implementation

int arr[200020];
int bit_p[32];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t,n,p;
long long k;
int sol;
cin >> t;
while(t--){
cin >> n >> k;

//this resets the count of all bist to zero
for (int i = 0; i < 32; i++)
{
bit_p[i]=0;
}

//read on integer at a time
for (int i = 0; i < n; i++)
{
cin >> arr[i];
p=max_31;
//check from MSB 2 to the last bit and if any is set increase the bit count by one
for (int j = 1; j < 32; j++)
{
if (p&arr[i])
{
bit_p[j]++;
}
p>>=1;
}
//
}

//the bits are counted correctly i verified them
//you can verify by un commenting the below section

// for (int i = 0; i < 32; i++)
// {
//     cout > t;
while(t--){
cin >> n >> k;

//this resets the count of all bist to zero
for (int i = 0; i < 32; i++)
{
bit_p[i]=0;
}
//

//read on integer at a time
for (int i = 0; i < n; i++)
{
cin >> arr;
p=max_31;
//check from MSB 2 to the last bit and if any is set increase the bit count by one
for (int j = 1; j < 32; j++)
{
if (p&arr)
{
bit_p[j]++;
}
p>>=1;
}
//
}
//the bits are counted correctly i verified them
//you can verify by un commenting the below section

// for (int i = 0; i < 32; i++)
// {
//     cout 

Подробнее здесь: [url]https://stackoverflow.com/questions/79640279/my-c-code-behaviour-is-confusing-what-is-happening[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»