Submission
Status:
---------
Subtask/Task Score:
0/100
Score: 0
User: KanemiyaKana
Problemset: บวกเลขฐาน
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-02 16:38:58
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
int main()
{
int all[4][4];
for (int i = 0; i < 4; i++)
{
int value = 0;
int count = 0;
int line[4];
string input;
getline(cin, input);
stringstream ss(input);
while(ss >> value)
{
count++;
if (count > 4)
{
cout << "Wrong format, please make sure there are exactly 4 numbers on each line.";
return 0;
}
line[count - 1] = value;
}
if (count < 4)
{
cout << "Wrong format, please make sure there are exactly 4 numbers on each line.";
return 0;
}
for (int j = 0; j < 4; j++)
{
all[i][j] = line[j];
}
}
int total = 0;
int reversetotal = 0;
for (int i = 0; i < 4; i++)
{
total = total + all[i][i];
}
for (int i = 3; i >= 0; i--)
{
reversetotal = reversetotal + all[i][i];
}
cout << total << " " << reversetotal;
}