ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

не могу понять, почему не принимает програму (задача 1243)
Posted by Bohdan 26 Mar 2017 20:14
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    char N[51];
    cin >> N;
    int i;
    for (i = 0; N[i] != '\0'; i++);
    char Y[4];
    int counter = 0, a = 0;
    if (i % 3 == 0)
    {
        for (int j = 0; j < i; j += 3)
        {
            Y[0] = N[j];
            Y[1] = N[j + 1];
            Y[2] = N[j + 2];
            Y[3] = 0;
            if (counter % 2 == 0)
            {
                int temp = atoi(Y);
                a += temp;
            }
            if (counter % 2 == 1)
            {
                int temp = atoi(Y);
                a -= temp;
            }
            counter++;
        }
    }
    if (i % 3 != 0)
    {
        int start = i % 3;
        for (int maloe = 0; maloe < start; maloe++)
        {
            Y[maloe] = N[maloe];
        }
        Y[start] = '\0';
        int temporary = atoi(Y);
        a -= temporary;
        int counter = 0;
        for (int j = start; j < i; j += 3)
        {
            Y[0] = N[j];
            Y[1] = N[j + 1];
            Y[2] = N[j + 2];
            Y[3] = 0;
            if (counter % 2 == 0)
            {
                int temp = atoi(Y);
                a += temp;
            }
            if (counter % 2 == 1)
            {
                int temp = atoi(Y);
                a -= temp;
            }
            counter++;
        }
    }

    cout << abs(a%7);
    system("pause");
    return 0;
}
Re: не могу понять, почему не принимает програму (задача 1243)
Posted by Bohdan 26 Mar 2017 20:17
Я делаю ввод в строку, тогда считываю по 3 элемента и делаю их один числом (например, 123456 в числа 123 и 456), тогда по признаку деления на 7 узнаю остаток. Если число, например 12435 то я делю его на 12 и 435 и по работаю по тому же принципу. На моих проверках всё работает хорошо, а система выдаёт WA на 3 тесте.
Re: не могу понять, почему не принимает програму (задача 1243)
Posted by ToadMonster 26 Mar 2017 23:04
Could you please open task-related themes in task discussions rather than common?

Could you please publish link to mathematical background of your solution?
Btw,
Test your solution on numbers 222223 and 223222.

Could you please read task discussions and find simple division digit-by-digit in the every second topic?

Edited by author 26.03.2017 23:20
Re: не могу понять, почему не принимает програму (задача 1243)
Posted by Themistoclus 4 Apr 2017 14:49
Сударь, вы очень-очень мудрёно решаете. Код этой задачи - в несколько строк.