ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1581. Teamwork

It is very easy, here is my solution
Posted by Dimaphil 7 Nov 2009 02:05
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
Posted by 6109Antony 26 Nov 2012 23:43
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
Posted by competitivecoder 4 Jun 2015 09:13
#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;
}