text
stringlengths
49
983k
#include <bits/stdc++.h> #define REP(i,n,N) for(int i=n;i<N;i++) #define p(S) cout<<(S)<<endl #define ck(a,b) (0<=(a)&&(a)<(b)) using namespace std; int main(){ int n; while(cin>>n,n){ string s; pair<int,int> now={0,0}; bool b=true;//true:floor int ans=0; REP(i,0,n){ cin>>s; if(s=="lu") now.first=1; else if(s=="ru") now.second=1; else if(s=="ld") now.first=0; else if(s=="rd") now.second=0; if((now==make_pair(1,1)&&b)||(now==make_pair(0,0)&&!b)){ ans++; b=!b; } } p(ans); } return 0; }
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <limits.h> int main() { int i,j; int n; int ans; char a[3],b[3]; while(1) { scanf("%d",&n); if(n==0){break;} else { ans=0; for(i=0;i<(n/2);i++) { scanf("%s %s",a,b); if((a[0]!=b[0])&&(a[1]==b[1])) { ans++; } } if(n%2==1){scanf("%s",b);} } printf("%d\n",ans); } return 0; }
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<vector> #include<unordered_map> using namespace std; int main() { string a[100]; int b; while (cin >> b, b) { for (int c = 0; c < b; c++)cin >> a[c]; int s = 0; for (int d = 0; d < b - 1; d++) { if (a[d][1] == a[d + 1][1])s++; } cout << s << endl; } }
#include<iostream> using namespace std; int main(){ while(1){ int n,c=0; cin>>n; if(n==0)break; string s,b; for(int i=0;i<n;i++){ cin>>s; if(s[0]!=b[0]&&s[1]==b[1])c++; b=s; } cout<<c<<endl; } return 0; }
#include<iostream> #include<string> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) using namespace std; int main(){ int n; while(cin>>n,n){ string s; int ans=0; bool pre=false,r=false,l=false; rep(i,n){ cin>>s; if(s=="lu")l=true; if(s=="ru")r=true; if(s=="ld")l=false; if(s=="rd")r=false; if(pre==false && r==true && l==true){ ans++; pre=true; } if(pre==true && r==false && l==false){ ans++; pre=false; } } cout<<ans<<endl; } return 0; }
#include "bits/stdc++.h" using namespace std; int main() { int N; while (cin >> N) { if (N == 0) return 0; vector<int> V(N); for (int i = 0; i < N; i++) { char C, D; cin >> C >> D; if (C == 'l') V[i] = 0; else V[i] = 1; } int ANS = 0; for (int i = 0; i < N / 2; i++) { ANS += V[i * 2] != V[i * 2 + 1]; } cout << ANS << endl; } }
#include <iostream> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) int main(){ while(1){ int n; cin >> n; if(n==0)break; string s; int r=0,l=0,sum=0,ans=0; rep(i,n){ cin >> s; if(s[0] == 'l'){ if(l) l=0; else l=1; } if(s[0] == 'r'){ if(r) r=0; else r=1; } if(sum == 0 && r+l == 2){ sum = 2; ans++; } else if(sum == 2 && r+l==0){ sum = 0; ans++; } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ int n; while(cin>>n,n){ bool exercise=true,right=false,left=false; string input; int cnt=0; for(int i=0;i<n;i++){ cin>>input; if(input=="lu")left=true; else if(input=="ru")right=true; else if(input=="ld")left=false; else right=false; if(exercise==true&&right==true&&left==true){ exercise=false; cnt++; }else if(exercise==false&&right==false&&left==false){ exercise=true; cnt++; } } cout<<cnt<<endl; } }
#include <iostream> using namespace std; int main() { int n; while(cin >> n, n) { int count = 0; for(int i = 0; i < n / 2; ++i) { string op1, op2; cin >> op1 >> op2; if((op1 == "lu" && op2 == "ru") || (op1 == "ru" && op2 == "lu") || (op1 == "ld" && op2 == "rd") || (op1 == "rd" && op2 == "ld")) ++count; } if(n % 2) { string a; cin >> a; } cout << count << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main(){ int n; string s[155]; while(1){ cin>>n; if(n==0)break; bool left=false,right=false; int cnt=0; for(int i=0;i<n;i++) cin>>s[i]; for(int i=0;i<n-1;i++){ if((s[i+1]=="lu"&&s[i]=="ru")||(s[i]=="lu"&&s[i+1]=="ru")){ i++; cnt++; }else if((s[i+1]=="ld"&&s[i]=="rd")||(s[i]=="ld"&&s[i+1]=="rd")){ i++; cnt++; } } cout<<cnt<<endl; } return 0; }
//Step Aerobics #include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) int main(){ while(true){ int n; cin>>n; if(n==0)break; vector<string> v; rep(i,n){ string s; cin>>s; v.push_back(s); } int cnt=0; rep(i,n-1){ if((v[i]=="lu"&&v[i+1]=="ru")||(v[i]=="ru"&&v[i+1]=="lu") ||(v[i]=="ld"&&v[i+1]=="rd")||(v[i]=="rd"&&v[i+1]=="ld")){cnt++; i++;} } cout<<cnt<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; while(cin>>n,n) { string s; bool l=0,r=0,u=0; int ans=0; for (int i = 0; i < n; ++i) { cin>>s; if(s=="lu") l=1; else if(s=="ld") l=0; else if(s=="ru") r=1; else r=0; if(u&&!l&&!r) ++ans,u=0; else if(!u&&l&&r) ++ans,u=1; } cout<<ans<<endl; } return 0; }
#include<stdio.h> #include<iostream> #include<string> using namespace std; int main(){ string st; int n; while(1){ cin>>n;if(n==0)break; bool l=false,r=false,p=false; int c=0; for(int i=0;i<n;i++) { cin>>st; if(st=="ru")r=true; if(st=="rd")r=false; if(st=="lu")l=true; if(st=="ld")l=false; if(r&&l&&p==false){c++;p=true;} if(r==false&&l==false&&p==true){c++;p=false;} } cout<<c<<endl; } return 0; }
#include<iostream> #include<string> #include<vector> using namespace std; int main(void){ while(1){ int n; cin>>n; if(n==0)break; vector<string> s(n); for(int i=0;i<n;i++){ cin>>s[i]; } int ans=0; bool f=false; int r=0,l=0; for(int i=0;i<n;i++){ if(s[i]=="lu")l=1; if(s[i]=="ru")r=1; if(s[i]=="ld")l=0; if(s[i]=="rd")r=0; if(l==r){ if(r==1&&!f){ f=true; ans++; } if(r==0&&f){ f=false; ans++; } } } cout<<ans<<endl; } return 0; }
#include <stdio.h> int main() { int i,place,cou,a; char o[3],t[3],sute[3]; while(1){ scanf("%d",&a); if(a==0)break; cou=0; place=0; for(i=0;i<a/2;i++){ scanf("%s %s",o,t); //printf("%c %c\n",o[1],t[1]);/// if(place==0&&o[1]=='u'&&t[1]=='u'){ cou++; place=1; }else if(place==1&&o[1]=='d'&&t[1]=='d'){ cou++; place=0; } } if(a%2==1)scanf("%s",sute); printf("%d\n",cou); } return 0; }
#include<iostream> #include<string> using namespace std; int main(){ int n; while(cin>>n, n){ int cnt=0; string s[100]; for(int i=0;i<n;i++) cin>>s[i]; for(int i=1;i<n;i+=2) if(s[i-1][1]==s[i][1]) cnt++; cout<<cnt<<endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) #define all(a) a.begin(),a.end() #define o(a) cout<<a<<endl #define int long long using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; signed main(){ int n; string s; while(1){ int l=0,r=0,ans=0,pre=0; cin>>n; if(n==0) break; rep(i,0,n){ cin>>s; if(s=="lu") l=1; if(s=="ru") r=1; if(s=="ld") l=0; if(s=="rd") r=0; if(l==r && l!=pre){ ans++; pre=l; } } o(ans); } }
#include<bits/stdc++.h> using namespace std; int main(){ int n; string f[100]; map< string , string > str; str["lu"] = "ru"; str["ru"] = "lu"; str["ld"] = "rd"; str["rd"] = "ld"; while(cin >> n, n){ for(int i = 0; i < n; i++){ cin >> f[i]; } int cnt = 0; for(int i = 0; i < n - 1; i++){ cnt += (str[f[i]] == f[i + 1]); } cout << cnt << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int n; while (cin >> n, n) { int count = 0; bool next = true; bool L = false, R = false; for (int i = 0; i < n; i++) { string s; cin >> s; if (s == "lu") L = true; if (s == "ru") R = true; if (s == "ld") L = false; if (s == "rd") R = false; if (L == next && R == next) { next = !next; count++; } } cout << count << endl; } return 0; }
#include <iostream> using namespace std; int main(){ int n, t, ans, f; string s; while (cin >> n, n){ ans = 0; t = 0; f = 2; for (int i = 0; i < n; ++i){ cin >> s; if (s == "lu" || s == "ru") ++t; else --t; if (t == f){ ++ans; f = (f+2)%4; } } cout << ans << endl; } return 0; }
#include <iostream> #include <algorithm> using namespace std; int main(){ int n; while(cin>>n,n){ int cnt = 0; bool st = false; bool ron=false,lon=false; while(n--){ string s; cin>>s; if(s=="lu") lon=true; if(s=="ru") ron=true; if(s=="ld") lon=false; if(s=="rd") ron=false; if(!st & ron&lon){ ++cnt; st=true; } else if(st & !ron & !lon){ ++cnt; st=false; } } cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; while(cin >> n, n){ string prv = ""; int cnt = 0; while(n--){ string f; cin >> f; if(prv == "lu" && f == "ru" || prv == "ru" && f == "lu" || prv == "ld" && f == "rd" || prv == "rd" && f == "ld") cnt++; prv = f; } cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) int main() { while (1) { int n; cin >> n; if (n == 0) return 0; int f = 1; int l = 0, r = 0; int ans = 0; rep(i, 0, n) { string s; cin >> s; if (s == "lu") l = 1; else if (s == "ru") r = 1; else if (s == "ld") l = 0; else if (s == "rd") r = 0; if (f == l && f == r) { ans++; f = (f + 1) % 2; } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int n; string str[2]; string s[4] = {"lu","ru","ld","rd"}; int main(){ while(scanf("%d",&n),n){ int ans = 0; for(int i = 1; i < n; i += 2){ cin >> str[0] >> str[1]; if((str[0]==s[0]&&str[1]==s[1])||(str[0]==s[1]&&str[1]==s[0])||(str[0]==s[2]&&str[1]==s[3])||(str[0]==s[3]&&str[1]==s[2])) ans++; } if(n%2==1) cin >> str[0]; printf("%d\n",ans); } }
#include <bits/stdc++.h> using namespace std; #define int long long #define Rep(i, N) for(int i = 0; i < N; i++) string ch[] = {"ld", "rd", "lu", "ru"}; signed main() { int N; string S; while(cin >> N, N) { bool flag = false; int cnt = 0, bit = 3; Rep(i, N) { cin >> S; Rep(j, 4) { if(S == ch[j]) { bit |= 1 << j; bit &= ~(1 << ((j + 2) % 4)); } } if(flag && bit == 3) cnt++, flag = false; if(!flag && bit == 12) cnt++, flag = true; } cout << cnt << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; int main(void){ int n; string move[100]; while(cin >> n && n) { fill(move, move + 100, ""); char preUd = 'd', state = 'd'; int count = 0; for (int i = 0; i < n; ++i) { string move; cin >> move; char ud = move[1]; if (preUd == ud && state != ud) { ++count; state = ud; } preUd = ud; } cout << count << endl; } return 0; }
#include<iostream> #include<string> using namespace std; int main() { int N=0,out=0; string ashi1,ashi2; while(1) { cin >> N; if(N==0) break; for(int i=0;i<N/2;i++) { cin >> ashi1 >> ashi2; if((ashi1=="lu"&&ashi2=="ru")||(ashi1=="ru"&&ashi2=="lu")||(ashi1=="ld"&&ashi2=="rd")||(ashi1=="rd"&&ashi2=="ld")) out++; } if( N%2==1 )cin >> ashi1; cout << out << endl; out=0; } return 0; }
#include<iostream> #include<cstring> using namespace std; int main(){ string s; int n; while(cin>>n,n){ char c='0'; int ans=0; for(int i=0;i<n;i++){ cin>>s; if(c==s[1])ans++; c=s[1]; } cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define OUT(x) cout<<x<<endl int main(){ int n,ud,ans; bool o; string ins; while(cin>>n&&n){ o = false; ud = ans = 0; for(int i=0;i<n;i++){ cin >> ins; if(ins == "lu" || ins == "ru")ud++; else ud--; if(!o&&ud==2){ ans++; o = true; } else if(o&&!ud){ ans++; o = false; } } OUT(ans); } }
#include <bits/stdc++.h> using namespace std; int main() { int n; while(cin>>n,n){ string str; bool right=0,left=0; int ans=0; for(int i=0,now=1;i<n;i++){ cin>>str; if(str=="lu")left=1; if(str=="ru")right=1; if(str=="ld")left=0; if(str=="rd")right=0; if(now==right&&right==left){ ans++; now=(now+1)%2; } } cout<<ans<<endl; } }
#include<iostream> #include<string> using namespace std; int main(){ int n; while(cin >> n , n){ int cou = 0; string str[101]; for(int i=0;i<n;i++){ cin >> str[i]; if(i % 2 == 1){ if(str[i][1] == 'u' && str[i-1][1] == 'u') cou++; else if(str[i][1] == 'd' && str[i-1][1] == 'd') cou++; } } cout << cou << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) using namespace std; int main(){ int n; while(cin >> n, n){ int l=0, r=0, b=1; int count=0; rep(i,n){ string f; cin >> f; if( f[0] == 'l' ){ l ^= 1; }else{ r ^= 1; } if( l == b && r == b ){ count++; b ^= 1; } } cout << count << endl; } return 0; }
#include <iostream> using namespace std; int main(){ int cnt,n; char f[3],st; while (1){ cin >> n; if (n==0)return 0; cnt=0; st='-'; for (int i=0;i<n;i++) { cin >> f; if (st=='-')st=f[0]; else{ if (st!=f[0]) { cnt++; } st='-'; } } cout << cnt << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main(){ int n; string s[155]; while(1){ cin>>n; if(n==0)break; int cnt=0; for(int i=0;i<n;i++) cin>>s[i]; for(int i=0;i<n-1;i++){ if((s[i+1]=="lu"&&s[i]=="ru")||(s[i]=="lu"&&s[i+1]=="ru")){ i++; cnt++; }else if((s[i+1]=="ld"&&s[i]=="rd")||(s[i]=="ld"&&s[i+1]=="rd")){ i++; cnt++; } } cout<<cnt<<endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int n = 0; for (; cin >> n, n != 0;) { string s = ""; int sum = 0; int u = 0; for (int i = 0;i<n; i ++) { cin >> s; if (s[1] == 'u')u++; else if (s[1] == 'd')u--; if (u == 2 || u==-2) { sum++; u = 0; } } cout << sum << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; int main(void) { int n = 1, ans = 0; cin >> n; while (n > 0) { vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < n-1; i++) { if (s[i][1] == s[i+1][1]) { ans++; } } cout << ans << endl; ans = 0; cin >> n; } return 0; }
#include<iostream> #include<cstdio> #include<string> using namespace std; int main(){ while(1){ int n,a=0,b=0,kai=0; string asi; cin>>n; if(n==0)break; for(int i=0;i<n;i++){ cin>>asi; if(asi[0]=='r'){ if(asi[1]=='u')a++; else a--; } if(asi[0]=='l'){ if(asi[1]=='u')b++; else b--; } if(kai%2==0&&a+b==2)kai++; if(kai%2==1&&a+b==0)kai++; } printf("%d\n",kai); } return 0; }
#include <iostream> #include <string> using namespace std; int main () { int n; while (cin >> n, n) { int r = 0, l = 0; int past = 0; int count = 0; while (n--) { string str; cin >> str; if (str == "lu") l = 1; else if (str == "ru") r = 1; else if (str == "ld") l = 0; else r = 0; if (!(r^l) && (r&l) != past) count++, past = r&l; } cout << count << endl; } return 0; }
#include <iostream> using namespace std; #define rep(i,n) for(int i=0;i<(int)n;i++) int main(){ while(1){ int n; cin >> n; if(n== 0) break; int l=0,r=0,wh=0,ans=0;; rep(i,n){ string s; cin >> s; if(s == "lu") l = 1; else if(s == "ld") l = 0; else if(s == "ru") r = 1; else if(s == "rd") r = 0; if(wh == 0 && l == 1 && r == 1){ ans++; wh = 1; } else if(wh == 1 && l == 0 && r == 0){ ans++; wh = 0; } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i=a;i<b;i++) #define rep(i,n) REP(i,0,n) int main() { int N; while(cin >> N && N){ string s; int prev = 0; int cnt = 0; bool l = 0, r = 0; rep(i, N) { cin >> s; if(s == "lu") { l = 1; } if(s == "ru") { r = 1; } if(s == "ld") { l = 0; } if(s == "rd") { r = 0; } if(!prev && l && r) { prev = 1; cnt ++; } else if(prev && !l && !r) { prev = 0; cnt ++; } } cout << cnt << endl;} return 0; }
#include<stdio.h> #include<iostream> using namespace std; int main(){ int n; int count; int i; string tmp,foot; while(1){ cin >> n; if(n == 0){ break; } count = 0; tmp = "ld"; for(i = 0 ; i < n ; i++){ cin >> foot; if((tmp == "ld" && foot == "rd")||(tmp == "lu" && foot == "ru")||(tmp == "rd" && foot == "ld")||(tmp == "ru" && foot == "lu")){ count++; } tmp = foot; } cout << count << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int n; string f[100]; int main() { while (cin >> n) { if (!n) break; int ans = 0; for (int i = 0; i < n; i++) cin >> f[i]; for (int i = 0; i < n / 2; i++) { if (f[2 * i][0] != f[2 * i + 1][0]) { ans++; } } cout << ans << endl; } return 0; }
#include <cstdio> #include <cstring> int main() { int n; while (true) { scanf("%d", &n); if (n == 0) break; int cnt = 0; bool ru = false, lu = false; for (int i=0;i<n;i++) { char f[3]; scanf("%s", f); if (!strcmp(f,"lu")) lu = true; else if (!strcmp(f,"ru")) ru = true; else if (!strcmp(f,"ld")) lu = false; else ru = false; if (lu == ru && (lu & ru) == !(cnt & 1)) cnt++; } printf("%d\n", cnt); } return 0; }
// Undone #include <bits/stdc++.h> #define int long long #define double long double #define INF 1e18 #define MOD 1000000007 using namespace std; signed main() { int N; while (cin >> N, N) { char last = ' '; int ans = 0; for (int i = 0; i < N; i++) { string s; cin >> s; if (last == s[1]) { ans++; } else { last = s[1]; } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int n; char buf[10000]; int main() { while (1) { scanf("%d", &n); if (n == 0) return 0; int cnt = 0; string prev; for (int i=0; i<n; i++) { scanf(" %s", buf); string s(buf); if (s == "lu" && prev == "ru") cnt++; if (s == "ld" && prev == "rd") cnt++; if (s == "ru" && prev == "lu") cnt++; if (s == "rd" && prev == "ld") cnt++; prev = s; } printf("%d\n", cnt); } }
#include <stdio.h> int main(){ int n,i,p; char f[100][2]; while(1){ scanf("%d",&n); if (n==0) break; p=0; for (i=0;i<n;i++){ getchar(); scanf("%c%c",&f[i][0],&f[i][1]); if (i!=0){ if ((f[i-1][0]!=f[i][0])&&(f[i-1][1]==f[i][1])){ p++; } } } printf("%d\n",p); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ for (int n; cin >> n, n;) { int cur = 0, prev = 0, cnt = 0; while (n--) { string f; cin >> f; if (f == "lu") cur |= 2; if (f == "ru") cur |= 1; if (f == "ld") cur &= 1; if (f == "rd") cur &= 2; if ((cur ^ prev) == 3) cnt++, prev = cur; } cout << cnt << endl; } }
#include <iostream> using namespace std; int main(){ int n; while(cin >> n, n){ string pre; cin >> pre; int cnt = 0; for(int i = 0; i < n - 1; i++){ string s; cin >> s; if(pre == "lu" && s == "ru" || pre == "ru" && s == "lu" || pre == "ld" && s == "rd" || pre == "rd" && s == "ld"){ cnt++; } pre = s; } cout << cnt << endl; } }
#include<bits/stdc++.h> using namespace std; int main(){ int n; while(1){ cin>>n; if(n==0){ break; } int leg[2]={0}; int cnt=0,last=0; string s; for(int i=0;i<n;i++){ cin>>s; if(s=="lu"){ leg[0]=1; }else if(s=="ru"){ leg[1]=1; }else if(s=="ld"){ leg[0]=0; }else{ leg[1]=0; } if(leg[0]==1&&leg[1]==1){ if(last==0){ cnt++; last=1; } }else if(leg[0]==0&&leg[1]==0){ if(last==1){ cnt++; last=0; } } } cout<<cnt<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { for(int n;cin>>n && n;){ int prev=0,res=0; int l=0,r=0; while(n--){ string s; cin>>s; if(s=="lu") l=1; if(s=="ru") r=1; if(s=="ld") l=0; if(s=="rd") r=0; if(l==r && l!=prev) prev=l,res++; } cout<<res<<endl; } }
#include <iostream> #include <string> #include <map> using namespace std; int main(){ int n; while(cin >> n, n){ string s; map<char , int> M; M['l'] = 0; M['r'] = 0; bool f = false; int ans = 0; for(int i = 0; i < n; ++i){ cin >> s; if(s[1] == 'u') ++M[s[0]]; if(s[1] == 'd') --M[s[0]]; if((!f) && M['l'] && M['r']){ f = true; ++ans; } if(f && M['l'] == 0 && M['r'] == 0){ ++ans; f = false; } } cout << ans << endl; } return 0; }
#include<iostream> using namespace std; int main() { int n; for(;cin>>n,n;) { bool l=false,r=false; bool next=true; int cnt=0; for(int i=0;i<n;i++) { string str; cin>>str; if(str=="lu") l=true; if(str=="ru") r=true; if(str=="ld") l=false; if(str=="rd") r=false; if(next==l && next==r) { cnt++; next=!next; } } cout<<cnt<<endl; } }
#include <bits/stdc++.h> using namespace std; bool solve(){ int n; cin >> n; if( n == 0 )return false; int now = 0; int le = 0,ri = 0,cnt = 0; for(int i=0;i<n;i++){ string s; cin >> s; if(s[0] == 'l'){ if(s[1] == 'u')le = 1; else le = 0; }else{ if(s[1] == 'u')ri = 1; else ri = 0; } if(le == 1 && ri == 1 && now == 0){ now = 1;cnt++; }else if(le == 0 && ri == 0 && now == 1){ now = 0;cnt++; } } cout << cnt << endl; return true; } int main(void){ while(solve()){} return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ while(1){ int n; queue<string> a; cin>>n; if(n==0){break;} for(int i=0;i<n;i++){ string w; cin>>w; a.push(w); } int r=0,l=0,count=0; pair<int,int> j; while(!a.empty()){ if(r==l){j=make_pair(2,r);} string w=a.front(); a.pop(); if(w=="lu"){l=1;} if(w=="ru"){r=1;} if(w=="ld"){l=0;} if(w=="rd"){r=0;} j.first--; if(j.first==0 && r==l && r!=j.second){ count++; } } cout<<count<<endl; } return 0; }
#include <iostream> #include <vector> #include <string> using namespace std; int main() { int n; while (cin >> n && n) { vector<string> f(n); for (int i = 0; i < n; ++i) cin >> f[i]; int cnt = 0; for (int i = 1; i < n; ++i) if (f[i - 1][1] == f[i][1]) cnt++, i++; cout << cnt << endl; } return 0; }
#include<iostream> using namespace std; int n; int main() { while(cin>>n,n) { string s;int flag=0,r=0,l=0,cnt=0; for(int i=0;i<n;i++) { cin>>s; if(s=="lu") { l=1; if(flag==0&&r==l)cnt++,flag=1; } else if(s=="ru") { r=1; if(flag==0&&r==l)cnt++,flag=1; } else if(s=="ld") { l=0; if(flag==1&&r==l)cnt++,flag=0; } else { r=0; if(flag==1&&r==l)cnt++,flag=0; } } cout<<cnt<<endl; } }
#include <stdio.h> int main(void) { while(true) { int n,res=0; bool l=false,r=false,last=false; scanf("%d", &n); if(!n) break; for(int i=0; i < n; i++) { char s[3]; scanf("%s", s); if(s[0] == 'l') l = !l; else r = !r; if( (l == r) && (l != last) ) { last = !last; res += 1; } } printf("%d\n", res); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { for(int n; cin >> n && n;) { int l = 0, r = 0, prev = 0, res = 0; for(int i = 0; i < n; ++i) { string s; cin >> s; if(s[0] == 'l') l ^= 1; else r ^= 1; if(l == r) { if(prev != l) ++res; prev = l; } } cout << res << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int i,n,ans=0,l=0,r=0,b=0; string a; while(1){ cin >> n; if(n==0) break; for(i=0;i<n;i++){ cin >> a; if(a=="lu"){ l=1; }else if(a=="ru"){ r=1; }else if(a=="ld"){ l=0; }else if(a=="rd"){ r=0; } if((l==1 && r==1) && b==0) { ans++; b=1; } if((l==0 && r==0) && b==1){ ans++; b=0; } } cout << ans << endl; ans=0; b=0; l=0;r=0; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; while(cin>>n,n){ bool l = false,r = false,now = true; int cnt = 0; for(int i = 0;i < n;i++){ string f; cin>>f; if(f[0] == 'l')l = !l; if(f[0] == 'r')r = !r; if(l==r && r==now){ now = !now; cnt++; } //cout<<"#"<<l<<" "<<r<<" "<<now<<endl; } cout<<cnt<<endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ while (1){ int n; cin >> n; if (n == 0){ break; } vector<string> f(n); for (int i = 0; i < n; i++){ cin >> f[i]; } int ans = 0; for (int i = 0; i < n - 1; i++){ if (f[i][0] != f[i + 1][0] && f[i][1] == f[i + 1][1]){ ans++; } } cout << ans << endl; } }
#include<iostream> #include<string> using namespace std; int main(){ int n; while(cin>>n,n){ string str,s[4]={"lu","ru","ld","rd"}; int f,ans=0; cin>>str; for(int i=0;i<4;i++){ if(str==s[i]) f=i; } for(int i=1;i<n;i++){ cin>>str; for(int j=0;j<4;j++){ if(str==s[j]){ if(f+j==1 || f+j==5){ ans++; } f=j; } } } cout<<ans<<endl; } return 0; }
#include<iostream> #include<string> using namespace std; int main(){ int n; int cnt; string move,bef; while(1){ cin>>n; if(n==0) break; bef="NO"; cnt=0; while(n--){ cin>>move; if(bef=="lu"&&move=="ru"||bef=="ru"&&move=="lu"||bef=="ld"&&move=="rd"||bef=="rd"&&move=="ld") cnt++; bef=move; } cout<<cnt<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; int rc,lc; int cnt; string str; int zen,now; while(cin>>n,n){ rc=lc=0; cnt=0; for(int i=0;i<n;i++){ cin>>str; if(str[0] == 'r')now = 0; else now = 1; if(str == "lu")lc++; if(str == "ru")rc++; if(str == "ld")lc--; if(str == "rd")rc--; if(lc == rc && zen != now)cnt++; zen = now; } cout<<cnt<<endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ int N; while( cin >> N && N){ string s; map<char,int> flag; int f = 0; int cnt = 0; for(int i = 0 ; i < N ; i++){ cin >> s; flag[s[0]] ^= 1; if( !f && flag['l'] && flag['r'] ){ f = 1; cnt++; } if( !flag['l'] && !flag['r'] ){ if(f){ cnt++; f = 0; } } } cout << cnt << endl; } }
#include <iostream> #include <string> #define rep(i, n) for(i = 0; i < n; i++) using namespace std; int n; string f[100]; int main() { int i; while (cin >> n) { if (!n) break; rep(i, n) cin >> f[i]; int ans = 0; for (i = 0; i + 1 < n; i += 2) { if (f[i][0] != f[i + 1][0]) { ans++; } } cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long signed main() { int N; while (cin >> N, N) { vector<bool> latte; for (int i = 0; i < N; i++) { string s; cin >> s; if (s == "lu" || s == "ru") latte.push_back(true); else latte.push_back(false); } int cnt = 0; for (int i = 1; i < N; i++) { if (latte[i] == latte[i - 1]) cnt++; } printf("%lld\n", cnt); } }
#include<iostream> #include<string> using namespace std; int main(){ int n; while(cin>>n &&n){ int ans=0; int l=0,r=0; for(int i=0;i<n;i++){ string str; cin>>str; if(str[0]=='l'){ if(l==1)l=0; else if(r==1){ ans++; r=l=0; } else l=1; } else { if(r==1)r=0; else if(l==1){ ans++; r=l=0; } else r=1; } } cout<<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ int n; vector<int> ans; while(cin >> n,n){ int count = 0; string s0 = "",s1; for(int i = 0;i < n;i++){ cin >> s1; if(s1 == "lu" && s0 == "ru")count++; if(s1 == "ru" && s0 == "lu")count++; if(s1 == "ld" && s0 == "rd")count++; if(s1 == "rd" && s0 == "ld")count++; s0 = s1; } ans.push_back(count); } for(int i = 0;i < ans.size();i++)cout << ans[i] << endl; }
#include <bits/stdc++.h> #define REP(i,n) for(int i=0;i<(int)(n);i++) using namespace std; int main() { while(1) { int n; cin>>n; if(!n)break; int cnt = 0; REP(i,n/2) { string s1,s2; cin>>s1>>s2; if (s1=="lu"&&s2=="ru") ++cnt; if (s1=="ru"&&s2=="lu") ++cnt; if (s1=="ld"&&s2=="rd") ++cnt; if (s1=="rd"&&s2=="ld") ++cnt; } if(n%2) { string s1; cin>>s1; } cout << cnt << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; while(1){ cin >> n; if(n == 0) break; int state = 0; int stt_r = 0; int stt_l = 0; int cnt = 0; string f; for(int i = 0;i < n;++i){ cin >> f; if(f == "lu") stt_l = 1; else if(f == "ru") stt_r = 1; else if(f == "ld") stt_l = 0; else if(f == "rd") stt_r = 0; if(state == 0 && stt_l == 1 && stt_r == 1){ cnt++; state = 1; } else if(state == 1 && stt_l == 0 && stt_r == 0){ cnt++; state = 0; } } cout << cnt << endl; } }
#include <iostream> #include <string> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) { break; } int r, l; r = l = 0; string s; int bb = 0; int ans = 0; for (int i = 0; i < n; i++) { cin >> s; if (s == "lu") { l++; } else if (s == "ru") { r++; } else if (s == "ld") { l--; } else { r--; } if (bb == 0 && l == 1 && r == 1) { ans++; bb = 1; } else if (bb == 1 && l == 0 && r == 0) { ans++; bb = 0; } } cout << ans << endl; } return 0; }
#include<iostream> #include<string> #include<cstdio> #include<algorithm> #include<stack> #include<queue> #include<vector> #include<cmath> #define ll long long int using namespace std; typedef pair<int, int> P; int main() { ll n; char foot[100][2]={}; int i; while(1){ cin>>n; if(n==0)break; int sum=0; for(i=0;i<n;i++) cin>>foot[i][0]>>foot[i][1]; for(i=1;i<n;i++){ if(foot[i-1][1]==foot[i][1]){ sum++; i++; } } cout<<sum<<endl; } }
#include <iostream> using namespace std; enum UESH { SHITA, UE }; int n; int main() { while (cin >> n) { if (n == 0) break; int res = 0; UESH le = SHITA, ri = SHITA, next = UE; for (int i = 0; i < n; ++i) { string str; cin >> str; if (str == "ld") le = SHITA; else if (str == "rd") ri = SHITA; else if (str == "lu") le = UE; else if (str == "ru") ri = UE; if (next == le && next == ri) { ++res; if (next == UE) next = SHITA; else next = UE; } } cout << res << endl; } }
#include<iostream> #include<vector> #include<string> using namespace std; vector<int> ans; int main(){ while(1){ int n; cin >> n; if(n == 0) break; bool fd = true; bool lf = true,rf = true; int count = 0; for(int i = 0;i < n;i++){ string f; cin >> f; if(f == "lu" || f == "ld") lf = !lf; else rf = !rf; if(lf == rf && lf != fd){ fd = !fd; count++; } } ans.push_back(count); } for(int i = 0;i < ans.size();i++) cout << ans[i] << endl; return 0; }
#include<iostream> #include<string> #include<algorithm> using namespace std; int main(){ int n; string x; while(cin >> n, n){ int l = 0, r = 0; int res = 0; int next = 1; for(int i = 0;i < n;i++){ cin >> x; if(x == "lu")l = 1; if(x == "ru")r = 1; if(x == "ld")l = 0; if(x == "rd")r = 0; if(l == next && r == next){ next ^= 1; res++; } } cout << res << endl; } return 0; }
#include<iostream> using namespace std; int main(){ int a=0,b=0, n[150], nos, sum[150]={0}; char str[150][100][3]; while(1){ cin >> n[a]; if (n[a]==0) break; for(b=0;b<n[a];b++){ cin >> str[a][b]; } a++; } nos = a; for(a=0;a<nos;a++) { for(b=0;b+1<n[a];b+=2) { if (str[a][b][0]-str[a][b+1][0]) sum[a]++; } cout << sum[a] << endl; } return 0; }
#include<iostream> using namespace std; int main(){ int n; string in,temp; while(1){ cin >>n; if(n == 0)break; int cnt=0; temp="ld"; for(int i=0 ; i < n ; i++){ cin >>in; if((temp == "ld" && in == "rd")|| (temp == "rd" && in == "ld")|| (temp == "lu" && in == "ru")|| (temp == "ru" && in == "lu") )cnt++; temp=in; } cout <<cnt<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++) int main() { while(true) { int N; cin >> N; if(N == 0) return 0; vector<string> F(N); rep(i, N) { cin >> F[i]; } int cnt = 0; rep(i, N / 2) { if(F[i * 2][0] != F[i * 2 + 1][0]) { cnt++; } } cout << cnt << endl; } }
#include<iostream> #include<string> using namespace std; int main() { int N=0,out=0; string ashi1,ashi2; while(1) { cin >> N; if(N==0) break; for(int i=0;i<N/2;i++) { cin >> ashi1 >> ashi2; if((ashi1=="lu"&&ashi2=="ru")||(ashi1=="ru"&&ashi2=="lu")||(ashi1=="ld"&&ashi2=="rd")||(ashi1=="rd"&&ashi2=="ld")) out++; } if(N%2==1) cin >> ashi1; cout << out << endl; out=0; } return 0; }
#include<iostream> using namespace std; int main(){ int n; while(cin>>n,n){ int c=0,u=0,d=0,l=-1; string str; for(int i=0;i<n;i++){ cin>>str; if(str=="lu"||str=="ru"){ if(l==0) c++; l=0; } if(str=="ld"||str=="rd"){ if(l==1) c++; l=1; } } cout<<c<<endl; } return 0; }
#include <iostream> using namespace std; void solve(int n) { int ans = 0; string t; cin >> t; for(int i=0; i<n-1; i++) { string s; cin >> s; if(t[0]!=s[0] and t[1]==s[1]) ans++; t = s; } cout << ans << "\n"; } int main() { int n; while(cin>>n && n) solve(n); return 0; }
#include <cstdio> #include <cstring> #include <string> #include <iostream> using namespace std; int n; string str; int main(void){ while(1){ scanf("%d",&n); if(n==0)break; bool left=false,right=false,lr=false; int cnt=0; for(int i=0;i<n;i++){ cin >> str; if(str=="lu")left=true; if(str=="ru")right=true; if(str=="ld")left=false; if(str=="rd")right=false; if(!lr && left && right){ cnt++; lr=true; } if(lr && !left && !right){ cnt++; lr=false; } } printf("%d\n",cnt); } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, m, n) for (int i = m; i < n; i++) #define rep(i, n) REP(i, 0, n) int main() { while (1) { int n; cin >> n; if (n == 0) break; vector<string> v(n); rep(i, n) cin >> v[i]; int cnt = 0; for (int i = 0; i + 1 < n; i += 2) { if (v[i][0] != v[i + 1][0]) cnt++; } cout << cnt << "\n"; } return 0; }
#include <iostream> #include <map> #include <cmath> using namespace std; int main() { int n; while ( cin >> n, n ) { map<string, int> conv; conv["lu"] = 0; conv["ru"] = 1; conv["ld"] = 0; conv["rd"] = 1; int cnt[2] = {0}; for (int i = 0; i < n; ++i) { string str; cin >> str; cnt[conv[str]]++; if (abs(cnt[0] - cnt[1]) >= 2) { int v = min(cnt[0], cnt[1]); cnt[0] = v; cnt[1] = v; } } cout << min(cnt[0], cnt[1]) << endl; } }
#include<bits/stdc++.h> using namespace std; int main(){ int n; while(cin>>n,n){ int c=0,a=0; for(int i=0;i<n;++i){ string s; cin>>s; if(s=="lu" || s=="ru"){ if(c==1) a++, c=0; else c=1; }else if(s=="ld" || s=="rd"){ if(c==-1) a++, c=0; else c=-1; } } cout<<a<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n; int main(){ // cin.tie(0); // ios::sync_with_stdio(false); while(1){ cin >> n; if(n == 0) return 0; int a = 0, b = 0, c = 0; for(int i=0; i<n; ++i){ string s; cin >> s; if(s == "lu") b += 2; else if(s == "ru") b += 1; else if(s == "ld") b -= 2; else b -= 1; if((b == 0 || b == 3) && b != c){ c = b; ++a; } } cout << a << "\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; while(cin>>n,n){ string str; bool right=0,left=0; int ans=0; for(int i=0,now=1;i<n;i++){ cin>>str; if(str=="lu")left=1; else if(str=="ru")right=1; else if(str=="ld")left=0; else right=0; if(now==right&&right==left){ ans++; now=(now+1)%2; } } cout<<ans<<endl; } }
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long int ll; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); while(1){ int n; cin >> n; if(n==0)break; int ans=0; int l=0,r=0; for(int i=0;i<n;i++){ string s; cin >> s; if(s=="lu")l++; if(s=="ld")l--; if(s=="ru")r++; if(s=="rd")r--; r=min(1,r); l=min(1,l); r=max(0,r); l=max(0,l); if(ans%2==0&&l*r==1)ans++; else if(ans%2&&l==0&&r==0)ans++; } cout << ans << endl; } }
#include <iostream> using namespace std; int main(void) { int n; int count; //昇降の回数をカウント string f; for(;;) { cin >> n; int array[n]; if(n == 0) break; for(int i=0;i<n;i++) { cin >> f; if(f == "lu") array[i] = 1; else if(f == "ru") array[i] = -1; else if (f == "ld") array[i] = 2; else if (f == "rd") array[i] = -2; } for(int i=0;i<n-1;i++) { if((array[i] + array[i+1]) == 0) count++; } cout << count << endl; count = 0; } }
#include<iostream> using namespace std; int main() { int n,sum=0; char Step[1000][2]; while(1){ cin>>n; if(n==0)break; for(int i=0;i<n;i++){ cin>>Step[i]; } for(int i=0;i<n-1;i++){ if(Step[i][0] !=Step[i+1][0] &&Step[i][1] ==Step[i+1][1])sum++; } cout <<sum<< endl; sum=0; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { while(1) { int n; cin >> n; if(n == 0) break; string f[110]; for(int i = 0; i < n; i++) { cin >> f[i]; } int prev = 0; int cnt = 0; int r = 0, l = 0; for(int i = 0; i < n; i++){ string t = f[i]; if(t == "lu") l++; else if(t == "ru") r++; else if(t == "ld") l--; else if(t == "rd") r--; if(r == l) { if(r - 1 == prev || r + 1 == prev) cnt++; prev = r; } } cout << cnt << endl; } return 0; }
#include<iostream> #include<string> using namespace std; int main(){ int n; while(cin>>n,n){ int mo[102]={0}; bool l=0,r=0; int cnt=0; string mae="tmp"; for(int i=0;i<n;i++){ string tmp; cin>>tmp; if(tmp=="lu")l=1; else if(tmp=="ru")r=1; else if(tmp=="ld")l=0; else if(tmp=="rd")r=0; if(r==l&&mae[0]!=tmp[0])cnt++; mae=tmp; } cout<<cnt<<endl; } return 0; }
#include<iostream> using namespace std; int main(){ string s; int sum; string prev; int n; while(cin >> n){ if(n==0){break;} sum=0; cin >> s; prev = s; for(int i=1; i<n; i++){ cin >> s; if((prev=="lu"&&s=="ru") || (prev=="ru"&&s=="lu") || (prev=="ld"&&s=="rd") || (prev=="rd"&&s=="ld")){ sum++; } prev = s; } cout << sum << endl; } return 0; }
#include <iostream> #include <array> #include <string> using namespace std; int main(){ int n; while(cin >> n,n){ bool l = false,r = false; bool t = true; int ret = 0; for(int i=0;i<n;i++){ string s; cin >> s; if(s == "ru") r = true; if(s == "rd") r = false; if(s == "lu") l = true; if(s == "ld") l = false; if(r == t && l == t){ ret++; t = !t; } } cout << ret << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void){ int n; string s; int r,l;//0ならした int t;//0なら下にいる int i,j,k; int ans=0; while(true){ cin>>n; if(n==0)return 0; ans=0; r=0;l=0;t=0; for(i=0;i<n;i++){ cin>>s; if(s=="lu"){ l=1; } else if(s=="ru"){ r=1; } else if(s=="ld"){ l=0; } else if(s=="rd"){ r=0; } if(t==0&&r==1&&l==1){t=1;ans+=1;} if(t==1&&r==0&&l==0){t=0;ans+=1;} } cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; string s; int n,bf,r,l,cnt; int main(){ int i; while(1){ cin >> n; if(n==0)break; cnt=0; bf=0; r=0; l=0; for(i=0;i<n;i++){ cin >> s; if(s=="lu")l++; if(s=="ru")r++; if(s=="ld")l--; if(s=="rd")r--; if(l==r&&l!=bf){ bf=l; cnt++; } } cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; string s; int n; bool solve(){ cin >> n; if(n == 0){ return false; } int flag = 0; int a =0, b= 0; int ans = 0; for(int i=0;i<n;i++){ cin >> s; if(s == "lu"){ a = 1; }else if(s == "ru"){ b = 1; }else if(s == "ld"){ a = 0; }else{ b = 0; } if(!flag && a == 1 && b == 1){ ans++; flag = 1; }else if(flag && a == 0 && b == 0){ ans++; flag = 0; } } cout << ans << endl; return true; } int main(){ while(solve()); }
#include<bits/stdc++.h> #define REP(i,s,n) for(int i=s;i<n;i++) #define rep(i,n) REP(i,0,n) using namespace std; int main(){ int n; while( cin >> n, n ){ string s; int cnt = 0; bool L = false , R = false, phase = false; rep(_,n){ cin >> s; if( s[0] == 'l' ) L = !L; else R = !R; if( !phase && ( L && R ) ) { ++cnt; phase = !phase; } else if( phase && ( !L && !R ) ) { ++cnt; phase = !phase; } } cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool solve() { int N; cin >> N; if(!N) return false; int ans = 0; bool l = false, r = false; bool nxt = true; for(int i = 0; i < N; i++) { string s; cin >> s; bool &b = (s[0] == 'l' ? l : r); b = (s[1] == 'u' ? true : false); if(l == nxt && r == nxt) { ans++; nxt = !nxt; } } cout << ans << endl; return true; } int main() { while(solve()); return 0; }