Submission details
Task:ModAdd
Sender:dani28
Submission time:2016-09-24 16:13:19 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:20:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (i<=mystring.length()){
                             ^
input/code.cpp:25:33: error: variable-sized object 'out' may not be initialized
   int out[mystring.length()] = {};
                                 ^
input/code.cpp:27:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (k<mystring.length()){
                            ^
input/code.cpp:33:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i< mystring.length(); i++){
                                   ^
input/code.cpp:43:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (i<=mystring.length()){
                             ^
input/code.cpp:48:33: error: variable-sized object 'out' may not be initialized
   int out[mystring.length()...

Code

#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <string>
int main()
{
using namespace std;
ios::sync_with_stdio(0);
string a,b;
cin>>a;
cin>>b;
int diff;
int length_a = a.length();
int length_b = b.length();
if (length_a>length_b){
std::string mystring(length_a,'0');
diff = a.length() - b.length();
int i = diff;
int j = 0;
while (i<=mystring.length()){
mystring[i] = b[j];
i+=1;
j+=1;
}
int out[mystring.length()] = {};
int k = 0;
while (k<mystring.length()){
out[k]=(int(a[k])-48)+(int(mystring[k])-48);
out[k] = out[k]%10;
k+=1;
}
for(int i=0; i< mystring.length(); i++){
cout<<out[i];
}
}
else if (length_a<length_b){
std::string mystring(length_b,'0');
diff = b.length() - a.length();
int i = diff;
int j = 0;
while (i<=mystring.length()){
mystring[i] = a[j];
i+=1;
j+=1;
}
int out[mystring.length()] = {};
int k = 0;
while (k<mystring.length()){
out[k]=(int(b[k])-48)+(int(mystring[k])-48);
out[k] = out[k]%10;
k+=1;
}
for(int i=0; i< mystring.length(); i++){
cout<<out[i];
}
}
else {
int out[a.length()] = {};
int k = 0;
while (k<a.length()){
out[k]=(int(b[k])-48)+(int(a[k])-48);
out[k] = out[k]%10;
k+=1;
}
for(int i=0; i< a.length(); i++){
cout<<out[i];
}
}
return 0;
}