Moderator: Board moderators
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int main(){
char x[30];
char y[30];
int final[30];
char *xcopy, *ycopy;
int N, length1, length2, xtemp, ytemp, remember,temp, answer, modulus;
cin >> N;
int i=0;
while(i < N){
cin >> x >> y;
length1 = strlen(x);
int p = length1-1;
xcopy = new char[length1];
for(int t=0; t < length1; t++){
xcopy[t] = x[p];
p--;
}
length2 = strlen(y);
p = length2-1;
ycopy = new char[length2];
for(t=0; t < length2; t++){
ycopy[t] = y[p];
p--;
}
xtemp = atoi(xcopy);
ytemp = atoi(ycopy);
xtemp += ytemp;
t=1;
while(pow(10,t)/xtemp < 1)
t++;
temp= pow(10,t-1);
if(xtemp != temp*10){
remember= t;
while(t != 0){
temp= pow(10,t-1);
modulus = (xtemp % temp);
answer= ((xtemp - modulus) / temp);
final[t-1] = answer;
xtemp = modulus;
t--;
}
for(int b=0; b < remember; b++)
cout << final[b];
}
else{
cout << "1" << endl;
}
cout << endl;
delete [] xcopy;
delete [] ycopy;
i++;
}
return 0;
}
teste.cpp: In function `int main()':
teste.cpp:41: name lookup of `t' changed for new ISO `for' scoping
teste.cpp:29: using obsolete binding at `t'
teste.cpp:55: call of overloaded `pow(int, int&)' is ambiguous
/usr/include/bits/mathcalls.h:154: candidates are: double pow(double, double)
/usr/include/c++/3.2.3/cmath:427: long double std::pow(long
double, int)
/usr/include/c++/3.2.3/cmath:423: float std::pow(float, int)
/usr/include/c++/3.2.3/cmath:419: double std::pow(double, int)
/usr/include/c++/3.2.3/cmath:410: long double std::pow(long
double, long double)
/usr/include/c++/3.2.3/cmath:401: float std::pow(float, float)
teste.cpp:58: call of overloaded `pow(int, int)' is ambiguous
/usr/include/bits/mathcalls.h:154: candidates are: double pow(double, double)
/usr/include/c++/3.2.3/cmath:427: long double std::pow(long
double, int)
/usr/include/c++/3.2.3/cmath:423: float std::pow(float, int)
/usr/include/c++/3.2.3/cmath:419: double std::pow(double, int)
/usr/include/c++/3.2.3/cmath:410: long double std::pow(long
double, long double)
/usr/include/c++/3.2.3/cmath:401: float std::pow(float, float)
teste.cpp:66: call of overloaded `pow(int, int)' is ambiguous
/usr/include/bits/mathcalls.h:154: candidates are: double pow(double, double)
/usr/include/c++/3.2.3/cmath:427: long double std::pow(long
double, int)
/usr/include/c++/3.2.3/cmath:423: float std::pow(float, int)
/usr/include/c++/3.2.3/cmath:419: double std::pow(double, int)
/usr/include/c++/3.2.3/cmath:410: long double std::pow(long
double, long double)
/usr/include/c++/3.2.3/cmath:401: float std::pow(float, float)
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
char x[30];
char y[30];
char *xcopy, *ycopy;
int N, length1, length2, xtemp, ytemp, remember,temp, answer, modulus, *final;
cin >> N;
int i=0;
while(i < N){
cin >> x >> y;
length1 = strlen(x);
int p = length1-1;
xcopy = new char[length1];
for(int t=0; t < length1; t++){
xcopy[t] = x[p];
p--;
}
length2 = strlen(y);
p = length2-1;
ycopy = new char[length2];
for(int g=0; g < length2; g++){
ycopy[g] = y[p];
p--;
}
xtemp = atoi(xcopy);
ytemp = atoi(ycopy);
xtemp += ytemp;
int f=1;
while(pow(10,f)/xtemp < 1)
f++;
temp= pow(10,f-1);
final = new int[f];
if(xtemp != temp*10){
remember= f;
while(f != 0){
temp= pow(10,f-1);
modulus = (xtemp % temp);
answer= ((xtemp - modulus) / temp);
final[f-1] = answer;
xtemp = modulus;
f--;
}
int w=0;
for(int b=0; b < remember; b++){
if(w==0 && final[b] == 0)
continue;
else if(w==0 && final[b] != 0)
w++;
cout << final[b];
}
if(w==0)
cout << "0";
}
else{
cout << "1" << endl;
}
cout << endl;
delete [] xcopy;
delete [] ycopy;
delete [] final;
i++;
}
return 0;
}

Users browsing this forum: No registered users and 1 guest