Saratov State University :: Online Contester


::Go
- home
- news
- register
- update personal info
- problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

::Poll
Are you registered on Codeforces?
Yes
No
What is it???

[results]

::webboard

WA On test 4 , why?
Author: Sajjad Heydari
ID: 045970
Problem: 502
Contest: 0
Date: 2011-11-07 18:49:15

Hi , why i am getting WA on test 4?

First i will get n ; then i will push back digits to a vectore . After that i sort the vecotre and then use next permutation , then in a while which will finish after there is no next permutation, it check if the number %17==0

//502. Digits Permutation

#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> ans;
int main() {
unsigned long long n;
cin>>n;
while(n>0){
ans.push_back(n%10);
n/=10;
}
sort(ans.begin(),ans.end());
int size=ans.size();
do{
unsigned long long z=0;
for(int i=0;i<size;i++){
int a=1;
for(int j=1;j<=i;j++)
a*=10;
z+=a*ans[i];
}

if(z%17==0){
cout<<z;
return 0;
}
}while(next_permutation(ans.begin(),ans.end()));

cout<<-1<<endl;

return 0;
}

see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-11-22 04:48:11Online Contester Team © 2002 - 2016. All rights reserved.