|
|
вернуться в форумIt is very easy, here is my solution var a, b : array[1..1000] of integer; n, i, k : integer; begin readln(n); for i := 1 to n do begin read(a[i]); end; i := 2; k := 1; while i <= n + 2 do begin if a[i] = a[i - 1] then begin k := k + 1; i := i + 1; end else begin write(k,' ',a[i - 1],' '); i := i + 1; k := 1; end; end; end. Re: It is very easy, here is my solution Please explain, why my cod has WT7 and your not) var a:array[1..1000] of integer; i,n,k:integer; Begin readln(n); for i:=1 to n do begin read(a[i]); end; k:=1; i:=2; while i<=n+2 do begin if a[i]=a[i-1] then begin i:=i+1; k:=k+1; end else begin write(k,' ',a[i-1],' '); i:=i+1; k:=1; end; end; End. Edited by author 26.11.2012 23:44 Edited by author 26.11.2012 23:44 Re: It is very easy, here is my solution #include <bits/stdc++.h> using namespace std; #define maxx 500 #define pb push_back #define pii pair<int,int> queue<int>qu; vector<pii>vpii[maxx]; #define inf 0x7fffffff int X[]={+2,+2,-2,-2,+1,-1,-1,+1}; int Y[]={-1,+1,-1,+1,+2,+2,-2,-2}; int main() { int n,u; cin>>n; vector<int>v; for(int i=0;i<n;i++) { cin>>u; v.pb(u); } int cnt=1,l; for(int i=0;i<v.size();i++) { if(v[i]==v[i+1]) { cnt++; l=v[i+1]; } else{ l=v[i]; cout<<cnt<<" "<<l<<" "; cnt=1; } } return 0; } |
|
|