Uva 1583 – Digit Generator
/*
Uva 1583 – Digit Generator
Verdict : Accepted
Time : 0.629
Take a number. Subtract from 100. And then try add all digits with it’s own to check weather is it equal to the desired number or not.
If yes then print that number and break your loop. But be aware of your subtraction, if you don’t you may get TLE.
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <sstream>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#define sf scanf
#define pf printf
#define sfint scanf (“%d %d”,&a,&b)
#define sfl scanf (“%ld %ld”,&a,&b)
#define sfll scanf (“%lld %lld”,&a,&b)
#define sfd scanf (“%lf %lf”,&a,&b)
#define sff scanf (“%f %f”,&a,&b)
#define loop (i,n) for (i=0;i<n;i++)
#define LL long long
#define L long
#define nl puts(“”)
#define N 10000
#define MOD 10000000007
#define pb push_back
#define pi acos(-1.0)
#define sz size()
#define gc getchar ()
#define ps push
#define clr clear
#define bn begin()
#define ed end()
using namespace std;
int main ()
{
int t;
char num[15];
cin >> t;
while (t–)
{
L n,x,i,s;
bool f = false;
sf (“%ld”,&n);
x = (n-100);
for (i=x;i<n;i++)
{
s = i; //cout << s << ” “;
sprintf(num, “%ld” , i);
int len = strlen(num);
for (L j=0;j<len;j++)
{
s+=(num[j]-‘0’);
}
//cout << s << ” “;
if (s == n)
{
cout << i;
f = true;
break;
}
}
if (!f)
{
cout << “0”;
}
nl;
f = false;
}
return 0;
}
Uva 1583 – Digit Generator
Verdict : Accepted
Time : 0.629
Take a number. Subtract from 100. And then try add all digits with it’s own to check weather is it equal to the desired number or not.
If yes then print that number and break your loop. But be aware of your subtraction, if you don’t you may get TLE.
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <sstream>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#define sf scanf
#define pf printf
#define sfint scanf (“%d %d”,&a,&b)
#define sfl scanf (“%ld %ld”,&a,&b)
#define sfll scanf (“%lld %lld”,&a,&b)
#define sfd scanf (“%lf %lf”,&a,&b)
#define sff scanf (“%f %f”,&a,&b)
#define loop (i,n) for (i=0;i<n;i++)
#define LL long long
#define L long
#define nl puts(“”)
#define N 10000
#define MOD 10000000007
#define pb push_back
#define pi acos(-1.0)
#define sz size()
#define gc getchar ()
#define ps push
#define clr clear
#define bn begin()
#define ed end()
using namespace std;
int main ()
{
int t;
char num[15];
cin >> t;
while (t–)
{
L n,x,i,s;
bool f = false;
sf (“%ld”,&n);
x = (n-100);
for (i=x;i<n;i++)
{
s = i; //cout << s << ” “;
sprintf(num, “%ld” , i);
int len = strlen(num);
for (L j=0;j<len;j++)
{
s+=(num[j]-‘0’);
}
//cout << s << ” “;
if (s == n)
{
cout << i;
f = true;
break;
}
}
if (!f)
{
cout << “0”;
}
nl;
f = false;
}
return 0;
}
Comments
Post a Comment