10550  Combination Lock
Moderator: Board moderators

 Experienced poster
 Posts: 131
 Joined: Thu Apr 17, 2003 8:39 am
 Location: Baku, Azerbaijan
10550  Combination Lock
Hi. Can anyone explain how we have to turn the dial? I follow steps with sample inputs and don't get correct answers.
Thanks.
Thanks.
_____________
NO sigNature
NO sigNature

 Experienced poster
 Posts: 131
 Joined: Thu Apr 17, 2003 8:39 am
 Location: Baku, Azerbaijan
Here is problem statement:
Initial position 0
2 full turns = 720 degree
stop at the first number 10 = 720 + 90 = 810
1 full turn and return to the same place = 810 + 360 = 1170
turning counterclockwise from 1st position 10 to the 2nd 0 = 1170 + 90 = 1260
now the last turn clockwise from 2nd 0 to 3rd 10 = 1260 + 90 = 1350
The answer in sample output is 1890, but I didn't get the correct answer.
Which of this steps are wrong?
for example: 0 10 0 10turn the dial clockwise 2 full turns
stop at the first number of the combination
turn the dial counterclockwise 1 full turn
continue turning counterclockwise until the 2nd number is reached
turn the dial clockwise again until the 3rd number is reached
pull the shank and the lock will open.
Initial position 0
2 full turns = 720 degree
stop at the first number 10 = 720 + 90 = 810
1 full turn and return to the same place = 810 + 360 = 1170
turning counterclockwise from 1st position 10 to the 2nd 0 = 1170 + 90 = 1260
now the last turn clockwise from 2nd 0 to 3rd 10 = 1260 + 90 = 1350
The answer in sample output is 1890, but I didn't get the correct answer.
Which of this steps are wrong?
_____________
NO sigNature
NO sigNature
 little joey
 Guru
 Posts: 1080
 Joined: Thu Dec 19, 2002 7:37 pm
10550 Why WA?
I don't know why WA...but sample input gives correct answer...anyone help me....
#include <stdio.h>
void main(){
long int a, b, c, d, sum,temp;
while(scanf("%ld %ld %ld %ld",&a,&b,&c,&d)){
if(a==0&&b==0&&c==0&&d==0)break;
sum=1080;
temp=(ab);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp;
temp=(bc);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp;
temp=(cd);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp;
printf("%ld\n",sum);
}
}
#include <stdio.h>
void main(){
long int a, b, c, d, sum,temp;
while(scanf("%ld %ld %ld %ld",&a,&b,&c,&d)){
if(a==0&&b==0&&c==0&&d==0)break;
sum=1080;
temp=(ab);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp;
temp=(bc);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp;
temp=(cd);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp;
printf("%ld\n",sum);
}
}
Hi Xander,
Your technique is not quite correct. I have made few modifications and got it AC.
this part of your code is wrong :
if(temp<0)temp=temp*(1);
sum=sum+3609*temp
instead of multiplying by 1, add 40 to tmp if necessary.
and sum = sum + 9*temp;
Hope it helps.
Your technique is not quite correct. I have made few modifications and got it AC.
this part of your code is wrong :
if(temp<0)temp=temp*(1);
sum=sum+3609*temp
instead of multiplying by 1, add 40 to tmp if necessary.
and sum = sum + 9*temp;
Hope it helps.
Last edited by sohel on Sat Dec 20, 2003 10:15 am, edited 1 time in total.
I need Sapmle Input
Can any one give me more sample input...I want to judge my program why this is WA?
Thanks Everyone
Thanks Everyone
Xander,
Remember from 2nd number to 3rd number the lock is moved counterclockwise. so instead of
temp=(bc);> temp=(cb);
change
[cpp]
sum=1080;
temp=(ab);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp;
temp=(bc);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp;
temp=(cd);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp
[/cpp]
to
[cpp]
sum=1080;
temp=(ab);
if(temp<0)temp=temp+40;
sum=sum+9*temp;
temp=(cb);
if(temp<0)temp=temp + 40;
sum=sum+9*temp;
temp=(cd);
if(temp<0)temp=temp + 40;
sum=sum+9*temp
[/cpp]
hope it helps.
Remember from 2nd number to 3rd number the lock is moved counterclockwise. so instead of
temp=(bc);> temp=(cb);
change
[cpp]
sum=1080;
temp=(ab);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp;
temp=(bc);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp;
temp=(cd);
if(temp<0)temp=temp*(1);
sum=sum+3609*temp
[/cpp]
to
[cpp]
sum=1080;
temp=(ab);
if(temp<0)temp=temp+40;
sum=sum+9*temp;
temp=(cb);
if(temp<0)temp=temp + 40;
sum=sum+9*temp;
temp=(cd);
if(temp<0)temp=temp + 40;
sum=sum+9*temp
[/cpp]
hope it helps.
I'm confused with clockwise and counterclockwise...
here is my code, and it's AC ...
But I still can't realise why ..... @_____@
[cpp]
#include <iostream>
using namespace std;
int turn (int a,int b,int d) {
if (d) { // clockwise
if (b>a) return (ba);
else return (40a+b);
}
else {
if (a>b) return (ab);
else return (40b+a);
}
}
int main() {
int a,b,c,d,s;
while (cin >>a>>b>>c>>d) {
if (!a&&!b&&!c&&!d) break;
s = 120;
s+=turn(a,b,0); // why here is counterclockwise ?!
s+=turn(b,c,1);
s+=turn(c,d,0);
cout << s*9 << endl;
}
return 0;
}
[/cpp]
here is my code, and it's AC ...
But I still can't realise why ..... @_____@
[cpp]
#include <iostream>
using namespace std;
int turn (int a,int b,int d) {
if (d) { // clockwise
if (b>a) return (ba);
else return (40a+b);
}
else {
if (a>b) return (ab);
else return (40b+a);
}
}
int main() {
int a,b,c,d,s;
while (cin >>a>>b>>c>>d) {
if (!a&&!b&&!c&&!d) break;
s = 120;
s+=turn(a,b,0); // why here is counterclockwise ?!
s+=turn(b,c,1);
s+=turn(c,d,0);
cout << s*9 << endl;
}
return 0;
}
[/cpp]
Thanks for your help !
10550  WA
[cpp]#include <iostream.h>
#include <stdio.h>
int main()
{
int a,b,c,d,sum;
while(cin>>a>>b>>c>>d)
{
if(a==0&&b==0&&c==0&&d==0) break;
sum=1080+(120+a2*b+2*cd)*9;
cout<<sum<<endl;
}
return 0;
}[/cpp]
I dont know where goes wrong but I got WA all the time,can u give me some test data??thx!
#include <stdio.h>
int main()
{
int a,b,c,d,sum;
while(cin>>a>>b>>c>>d)
{
if(a==0&&b==0&&c==0&&d==0) break;
sum=1080+(120+a2*b+2*cd)*9;
cout<<sum<<endl;
}
return 0;
}[/cpp]
I dont know where goes wrong but I got WA all the time,can u give me some test data??thx!

 New poster
 Posts: 17
 Joined: Thu Jul 15, 2004 10:55 am
 Location: Poland, Rzeszow University of Technology
Re: 10550  WA
You should write the code like this:
[cpp]#include <iostream>
using namespace std;
/* code */
[/cpp]
1) there is no need to include stdio, if you use only cin and cout
2) declaration of iostream was wrong  but this cause only warning message
And the major problem, you calculate the output in wrong way. Try this:
[cpp]#include <iostream>
using namespace std;
/* code */
[/cpp]
1) there is no need to include stdio, if you use only cin and cout
2) declaration of iostream was wrong  but this cause only warning message
And the major problem, you calculate the output in wrong way. Try this:
Output for this test is:5 15 35 5
5 15 25 35
0 0 0 0
1800
1710