Edited by author 06.01.2021 17:11 Are multiple '1' digits possible in the circle ? If yes , then will they produce separate click if they are currently in the window ? #include <iostream> #include <string> using namespace std; int main() { string a[3000]; int n; int m; cin >> n; cin >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } int j = m; for (int i = 0; i < 10; i++) { cout << a[j]; j++; if (j == n ) { j = 0; } } cout << endl; return 0; } add ""cout<<flush;"" in diffrent places and see if it works(sometimes solves the error) string a[3000]; Hmm. It's really funny to use string array for containing int values. Edited by author 13.04.2014 14:08 1 ≤ M ≤ 32767. and you are trying to print a[j] which j >= m m can be above n; m can be above a length. To put big arrays on stack is a bad idea. a should be dynamic array or vector. I THINK THAT MY PROGRAM MUST HAVE AC BUT WA3 WHAT THE 3 TEST???? PLEASE POST TEST №3!!!!!!! Edited by author 13.05.2007 15:12 blonde :) ha ha. It is joke about WRITING MESSAGES WITH CAPS LOCK ON Which difference write messages WITH CAPS LOCK ON or with caps lock off? Please post some tests! I dont know why my program had WA :( 12 335 1 2 3 4 5 6 7 8 9 0 7 7 answer 7123456789 Thanks for the test, I've got AC! #include <iostream> #include <algorithm> using namespace std; int main() { int i,n,m; cin>>n>>m; long int *a=new long int [n]; for(i=0;i<n;i++) cin>>a[i]; rotate(a,a+m,a+n); long int b[10]; for(i=0;i<10;i++) b[i]=a[i]; for(i=0;i<10;i++) cout<<b[i]; cout<<endl; return 0; } the test of Alias doesn't work,but why?What is incorrect in code? Already got AC....this code is right,you only need to decrease the quantity of ranges by decreasing the "m".......make m<n and everything will be ok ;) Or you can use "%" :) And yes,i'm necroposter ))) It's just the array rotation problem asked of a different way. import java.util.Scanner; public class _1370 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int digitos = in.nextInt(); int cliques = in.nextInt(); String saida = ""; String parte2 = ""; for (int i = 1; i <= cliques; i++){ saida += in.nextInt(); } for (int i = cliques+1; i <= digitos; i ++){ parte2 += in.nextInt(); } parte2 += saida; System.out.println( parte2.substring(0,10) ); } } you are using in.nextInt() to get the input from the user for a String. That is used for integers. You should be using in.next() or in.nextLine() for String. then how the heck does it happen that "after one click the first digit will go out of site and the 11-th digit will become visible." Edited by author 11.08.2013 03:47 #include <iostream.h> int main() { int N,M,i,t; cin>>N>>M; int *mas=new int [N]; int *mas2=new int [N]; for(i=1;i<=N;i++) cin>>mas[i]; for(i=1;i<=N;i++) { t=i+M; if(t>N) { t-=N; } mas2[t]=mas[i]; } if(N>10) { for(i=3;i<=N;i++) cout<<mas2[i]; } else { for(i=1;i<=N;i++) cout<<mas2[i]; } return 0; } If you wnat to use cin and cout you must write using namespace std; Look how to use STL algorithm rotate(). It's very easy: rotate(arr, arr + k, arr + N); Thanks !!! I think it will be helpful in the future. "Write the number that will appear in the window of the magic machine after the rotation." I think 'number' is not a correct definition of a sequence of digits with possible leading zeros. So 8907712345 is number, but 0771234589 is not. So I propose to replace 'number' with 'sequence of digits'. #include<stdio.h> main() { int N,M,a[1000],i; scanf("%i %i",&N,&M); for(i=0;i<N;i++)scanf("%i",&a[i]); for(i=M;i<M+10;i++)printf("%i",a[i%N]); } use queue Edited by author 25.08.2011 19:25 по одной цифре в линии -> по одной цифре в строке THIS OUR PROGRAMM: program magician; {$APPTYPE CONSOLE} uses SysUtils; Var i,j,n,m,k,t:integer; a:array[1..10000] of integer; begin readln(n,m); for i:=1 to n do readln(a[i]); if(m>n) then m:=m mod n; t:=0; i:=m; repeat i:=i+1; t:=t+1; write(a[i]); if i=n then i:=0; until t=10; end. Maybe you should input(n=12,m=12)to check your error. WHY WA#4???? #include<stdio.h> #include<math.h> void main(){ int v=0,m,n; scanf("%d",&n); int* a=new int[n]; int* b=new int[n]; int* c=new int[n]; scanf("%d",&m); for (int i=1;i<=n;i++){ scanf("%d",&a[i]); } if(m+11<=n){ for(int j=m+1;j<=11+v;j++){ b[j]=a[j];} for(int j=m+1;j<=11+v;j++){ printf("%d",b[j]); } } else { v=m; while(v>n){ v=abs(v-n); } for(int i=v+1;i<=n;i++){ b[i]=a[i];} for(int k=1;k<=10-(n-v);k++){ c[k]=a[k];} for(int i=v+1;i<=n;i++){ printf("%d",b[i]); } for(int k=1;k<=10-(n-v);k++){ printf("%d",c[k]); } } } Your program always must output 10 digits. Try this test: 15 16 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 Thank you,Sergey Lazarev!=) Write in Russia; DEJSTVITELNO HOTJABY DVA VARIANTA Edited by author 06.09.2005 21:19 Я с ним согласен пишите на руском!!! I AGREE WITH HIM WRITE IN RUSSIAN!!! вы досих пор не можете перевести!!! Edited by author 16.03.2009 21:05 Edited by author 16.03.2009 21:05 import java.util.Scanner; public class Magician { public static void main(String[] args) { Scanner in = new Scanner(System.in);
int digitos = in.nextInt(); int cliques = in.nextInt(); String saida = ""; String parte2 = "";
for (int i = 1; i <= cliques; i++){ saida += in.nextInt(); }
for (int i = cliques+1; i <= digitos; i ++){ parte2 += in.nextInt(); } parte2 += saida;
System.out.println( parte2.substring(0,10) ); } } I can't see, why its crashing I can't understand what's wrong with this C++ code:
unsigned n, m, index = 0; cin >> n >> m;
char *seq = new char[n]; for(int i = 0; i < n; ++i) cin >> seq[i]; for(int i = m; i < n; ++i) cout << seq[i];
for(int i = n-m; i < 10; ++i) cout << seq[index++]; You can take reminder (n%m) and write numbers from reminder+1 until 10. For example,use my AC code(C) #include <stdio.h> int N,M; int a[1000]; int i,j,z; int main() { scanf("%d%d",&N,&M); for (i=0;i<N;i++) { scanf("%d",&a[i]); } z=M%N; N--; j=z; i=0; while (i<10) { printf("%d",a[z]); if (z==N) z=0; else z++; i++;
} printf("\n"); return 0; } [code deleted] Edited by author 16.04.2007 22:52 MAY BE ANY ERROR IN ALGORITHM! MYBE YOU KILL YOUR SELF? DO NOT USE BIG LETTERS! IT'S VERY VERY BAD! AT FIRST IT ISN'T BIG,AT 2-ND DON'T SAY ME WHAT I MUST DO! think about this case when n = 1000, and m = 32000 use % operation THANK,I'LL THINK. look, n = 1000, m = 32000 seq = new __int64 [n]; // now seq is an array of 1000 int64 j = 0; for (i = n-m; i < 10; i++) // this cycle will be executed 31000 times printf("%I64d",seq[j++]) // and there will be acces vialation because j <= 31000, but seq is array [0..999] PS: it is very difficult to read text of your messages beacause of BIG LETTERS. I'ts really true. I spent more then 8 hour in my chair and look at my comptuter's monitor. my eyes very tired, but you don't listen in me. Edited by author 15.04.2007 23:22 [deleted] Edited by author 16.04.2007 22:53 3 4 4 3 5 1 you program don't work on these tests and don't combine cout/cin with printf/scanf Thank!!!but 11 ≤ n ≤ 1000!can n be <11? Edited by author 16.04.2007 21:13 Edited by author 16.04.2007 21:16 oh, sorry. of course not. n>=11 try this [ deleted] Edited by author 16.04.2007 22:54 thank you very much for good idea!AC now! Edited by author 16.04.2007 22:51 Why? Give me some tests, plz. |
|