|
|
back to boardJava or C++ problem !?!?!? Posted by Valiok 22 Jan 2015 05:03 Here is my java code : import java.util.Scanner; public class Example{ public static void main(String []args){ Scanner in = new Scanner(System.in); int number1,number2,number3; int [] array; int position=0; boolean check=false; int sth; number1=in.nextInt(); number2=in.nextInt(); number3=in.nextInt(); array = new int[number2]; for(int i=0;i<=number2-1;i++){ sth=(int)Math.pow(i,number1); if((sth-number3)%number2==0){ array[position]=i; position++; check=true; }else if(i==number2-1 && check==false){ System.out.println(-1); System.exit(0); }
} for(int p=0;p<position-1;p++){ for(int j=p+1;j<position;j++){ if(array[p]>array[j]){ int t=array[p]; array[p]=array[j]; array[j]=t; } } } for(int i=0;i<position;i++){ System.out.print(array[i] + " "); } System.out.println(); } } I get an error on test#3 . And on my C++ solution i get an error on test#6. #include<iostream> #include<cmath> using namespace std; int main(void){ unsigned short int N,M,Y; cin>>N>>M>>Y; unsigned short int X[M]; unsigned short int position=0; bool some_check=false; int sth; for(int i=0;i<=M-1;i++){ sth=pow(i,N); if((sth-Y)%M==0){ X[position]=i; position++; some_check=true; } else if(i==M-1 && some_check==false){ cout<<-1<<endl; return 0; } } for(unsigned short int i=0;i<position-1;i++){ for(unsigned short int j=i+1;j<position;j++){ if(X[i]>X[j]){ swap(X[i],X[j]); } } } for(unsigned short int i=0;i<position;i++){ cout<<X[i]<<" "; } cout<<endl; return 0; } Please,any ideas ??? Re: Java or C++ problem !?!?!? Posted by Victor 9 Nov 2017 19:46 |
|
|