1 solutions
-
0
C :
#include <stdio.h> int main() { int y ,k,n,x; while(scanf("%d%d%d",&y,&k,&n)!=EOF) { int i=0; for(x=1;x<=n-y;x++) { if((x+y)%k==0) { printf("%d ",x); i=1; } } if(i==1) printf("\n"); if(i==0) printf("-1\n"); } return 0; }C++ :
#include<iostream> #include<stdio.h> using namespace std; int main() { int y; int n; int k; //freopen("potatoes.in","r",stdin); //freopen("potatoes.out","w",stdout); while(scanf("%d%d%d",&y,&k,&n)!=EOF) { int sum; bool mark=0; for(int i = 1;i <= n/k;i++) { sum = k*i; if(sum-y>=1) { mark=1; printf("%d ",sum-y); } } if(!mark) { printf("-1\n"); } else { printf("\n"); } } return 0; } /* */ //#include <iostream> //#include <stdio.h> //#include <cstdlib> //#include <ctime> // //int main() //{ // freopen("potatoes.in","w",stdout); // srand(time(NULL)); // printf("10 1 10\n"); // printf("10 6 40\n"); // for(int i = 0;i < 50;i++) // { // int y = rand(); // int k = rand()%100+1; // int n = rand()%10000+1; // printf("%d %d %d \n",y,k,n); // } // return 0; //}Java :
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Iterator; import java.util.Scanner; public class Main { static StringBuffer sb= new StringBuffer(); /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new Main().method(); } public void method() { Scanner cin = new Scanner(System.in); int y=0, k=0, n=0; while (cin.hasNext()){ y = cin.nextInt(); k = cin.nextInt(); n = cin.nextInt(); ArrayList<Integer> result = new ArrayList<Integer>(); for(int x=1;x<n;x++){ if((x+y)<=n){ if((x+y)%k==0){ result.add(x); } } } if(result.isEmpty()){ System.out.print("-1"); } Iterator it = result.iterator(); StringBuffer sb = new StringBuffer(); while(it.hasNext()){ sb.append(it.next().toString()+" "); } System.out.println(sb); } } }
- 1
Information
- ID
- 1321
- Time
- 5000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- (None)
- # Submissions
- 0
- Accepted
- 0
- Uploaded By