prompt
string
response
string
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input().rstrip() work = [] countD = 0 for i in range(n): work.append(s[i]) for j in range(n-1): if work[j] == 'R' and work[j+1] == 'U' or work[j] =='U' and work[j+1] == 'R': work[j] = 'D' work[j+1] = 'D' countD += 1 print(n-countD)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
if __name__ == "__main__": n = int(input()) string = input() i = 0 count = 0 ans = n while i < n-1: if string[i] + string[i+1] == 'RU' or string[i] + string[i+1] == 'UR': ans -= 1 i += 1 i += 1 print(ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, s1; cin >> s; int len = s.length(); for (int i = 0; i < len; i++) { if (s[i] == 'U' && s[i + 1] == 'R' || s[i] == 'R' && s[i + 1] == 'U') { s[i] = ' '; s[i + 1] = ' '; s1 = s1 + "D"; i = i + 1; ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; using lint = long long; template <typename T> using vc = std::vector<T>; void solve(istream& cin, ostream& cout) { int n; string s; cin >> n >> s; int ans = n; for (int i = (1); i < int(n); ++i) { if (s[i - 1] != 'D' && s[i] != s[i - 1]) { ans--; s...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int gcd(int p, int q) { return q == 0 ? p : gcd(q, p % q); } int main() { int n; char s[110]; cin >> n >> s; int len = strlen(s); int ans = 0; for (int i = 0; i < len; ++i) { ans++; if (s[i] == 'R' && s[i + 1] == 'U') { ++i; } else if (s[i] == ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
size_path = int(input()) main_path = str(input()) main_path_list = [] for x in main_path: main_path_list.append(x) it = 0 while(it < len(main_path_list)-1): if main_path_list[it] == "R" and main_path_list[it+1] == "U": main_path_list[it] = "D" it += 1 elif main_path_list[it] == "U" and main_path_list[i...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(raw_input()) seq = raw_input() new_seq = "" while len(seq) > 1: temp = seq[0] + seq[1] if temp in ["RU", "UR"]: new_seq += "D" seq = seq[2::] else: new_seq += seq[0] seq = seq[1::] if len(seq) == 1: new_seq += seq[0] print len(new_seq)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int c = 0; for (int i = 0; i < n - 1;) { if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) { c++; i += 2; } else i++; } cout << n - c; return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; signed main() { int n, dem = 0; string s; cin >> n; cin >> s; s += 'X'; for (int i = 0; i < n; ++i) { if (s[i] == 'R' && s[i + 1] == 'U' || s[i] == 'U' && s[i + 1] == 'R') { dem++; i++; } else { dem++; } } cout << dem; return ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() ans = n used = [False for i in range(n)] for i in range(1, n): if not used[i - 1] and (s[i] == 'R' and s[i - 1] == 'U' or s[i] == 'U' and s[i - 1] == 'R'): ans -= 1 used[i] = True used[i - 1] = True print(ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; int n; char s[MAXN]; int main() { scanf("%d", &n); scanf("%s", s + 1); int ans = n; for (int i = 1; i <= n; i++) { if (s[i] != s[i + 1] && i != n) { ans--; i++; } } printf("%d\n", ans); return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.*; import java.lang.*; import java.math.BigInteger; import java.io.*; public class Main { public static void main(String [] args) throws Exception { OutputStream outputStream =System.out; PrintWriter out =new PrintWriter(outputStream); FastReader sc =new FastReader(); ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) a = list(input()) o = n h = False for i in range(n - 1): if h is False and (a[i] + a[i + 1] == "RU" or a[i] + a[i + 1] == "UR"): o -= 1 h = True else: h = False print(o)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; string s; int c, n; int main() { cin >> n >> s; for (int i = 1; i < n; i++) if (s[i] != s[i - 1]) { i++; c++; } cout << n - c << '\n'; return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) t=input() ans=0 i=0 while i<n: if i==n-1: ans+=1 break if t[i]=='R' and t[i+1]=='U': i+=1 elif t[i]=='U' and t[i+1]=='R': i+=1 ans+=1 i+=1 print(ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) s=input()+'k' x=0 i=0 while(i<n): if((s[i]=='R' and s[i+1]=="U") or (s[i]=='U' and s[i+1]=='R')): x=x+1 i=i+2 else: i=i+1 x=x+1 print(x)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) #pragma comment(linker, "/STACK:336777216") inline int nxt() { int x; scanf("%d", &x); return x; } inline long long lnxt() { long long x; scanf("%I64d", &x); return x; } const int N = (int)1e6 + 100; const int base = (int)1e9; con...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() p = 0 f = [] f.append(True) for i in range(1,len(s)): if s[i] != s[i-1] and f[i-1]: f.append(False) f[i] = False p += 1 else: f.append(True) print(n-p)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0; scanf("%d", &n); string s; cin >> s; for (int i = 0; i < s.size(); i++) { if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) { cnt++; i++; } } cout << n - cnt << endl; return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
inp = int(input()) seq = raw_input() new = "" i = 0 while i <= (inp)-1: sub = (seq[i:i+2]) #print(" "*i + sub) if sub == "UR" or sub == "RU": new += "D" i+=1 else: new += sub[0] i +=1 print(len(new))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Integer num = Integer.parseInt(br.readLine().trim()); String str ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; char a[101]; int ans = 0; scanf("%d", &n); scanf("%s", a); for (int i = 0; i < n; i++) { if (a[i] != a[i + 1]) i++; ans++; } printf("%d", ans); return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) s=input() f=[0]*n cnt=0 for i in range(n-1): if s[i]!=s[i+1] and not f[i]: f[i+1]=1 cnt+=1 print(n-cnt)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.util.Vector; import java.util.InputMismatchException; import java.io.IOException; import java.util.Stack; import java.io.InputStream; /** * Built using CHelper plug...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); // while (t > 0) { String s = sc.nex...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) t=list(input()) for i in range(len(t)-1): if t[i:i+2]==['U','R'] or t[i:i+2]==['R','U']: t[i:i+2]=['D'] print(len(t))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
a = int(raw_input()) b = raw_input() i = 0 while i < len(b)-1: if b[i:i+2] in ["UR","RU"]: i+=1 a-=1 i+=1 print a
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
//All CopyRights reserved GeeksforGeeks.com //Under the fair use(free use) Copyrights exception; //some codes are copied. import java.io.*; import java.util.*; import javax.xml.stream.events.Characters; public class Main { public static void main(String[] args)throws IOException { //the problem is about inscribt ci...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int l; string s, ss = ""; cin >> l; cin >> s; string ret = ""; for (int i = 0; i < s.size(); i++) { if (s[i] == 'R' && s[i + 1] == 'U') { ss += 'D'; i++; } else if (s[i] == 'U' && s[i + 1] == 'R') { ss += 'D'; i++; ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) s=list(input()) for i in range(n-1): if (s[i]=='U' and s[i+1]=="R") or (s[i]=='R' and s[i+1]=='U'): s[i+1]="D" print(len(s)-s.count("D"))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> int main() { char a[1000]; int i, j, d, n, len, len2; d = 0; j = 0; scanf("%d", &n); getchar(); gets(a); len = strlen(a); len2 = len; while (j < len - 1) { if (a[j] == 'R' && a[j + 1] == 'U') { len2 = len2 - 2; d++; j = j + 2; } else if (a[j] == 'U'...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.Scanner; public class DiagonalWalking { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(), i, l = n; String s = in.next(); for (i = 0; i < n - 1; i++) { if (s.charAt(i) == 'R' && s.charAt(i + 1) == 'U' || s.charAt(i) == 'U' && s.charAt(i +...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.BufferedReader; import java.io.InputStreamReader; public class DiagonalWalking { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int amountOfMoves = Integer.parseInt(reader.readLine()); S...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
from sys import stdin lines = stdin.readlines() n = lines[1][:-1] m = int(lines[0]) i = 0 summ = 0 while i < m-1: if n[i:i+2] == "RU" or n[i:i+2] == "UR": summ += 1 i += 2 else: i += 1 print m-summ
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; const int maxn = 105; int n; char a[maxn]; int main() { cin >> n; cin >> a; int res = 0; for (int i = 0; i < n - 1; ++i) { if (a[i] != a[i + 1]) { ++i; ++res; } } cout << n - res << endl; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = input() s = raw_input() i = 0 t = ["RU", "UR"] while (i < len(s)): if s[i:i+2] in t: s = s[0:i] + "D" + s[i+2:len(s)] i += 1 print len(s)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.Scanner; public class A954 { public static int getOptimizedPath(String str, int len) { int path = 0; for (int i = 0; i < len; i++) { char ch1 = str.charAt(i); char ch2 = i < len-1 ? str.charAt(i+1) : ' '; if ((ch1 == 'R' && ch2 == 'U') || (ch1 == 'U' && ch2 == 'R')) { ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.Scanner; public class diagnola_walking { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int len = sc.nextInt(); String str = sc.next(); String ans=""; for(int i=0; i<str.length(); i++) { if(i+1!=str.length() && str.charAt(i)=='R' && str.charAt(i+1)...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { string st, s = ""; int n; cin >> n; cin >> st; for (int i = 0; i < n; i++) { if (st[i] == 'U' && st[i + 1] == 'R') { s += "D"; i++; } else if (st[i] == 'R' && st[i + 1] == 'U') { s += "D"; i++; } else s += st[...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) l=list(input()) i=0 count=0 while i<n-1: if l[i]=="R" and l[i+1]=="U" or l[i]=="U" and l[i+1]=="R": i=i+2 count+=1 else: i+=1 print(n-count)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class tmp2{ public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); PrintWrite...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) m=0 r=input() i=0 while i <n-1: if r[i]!=r[i+1]: m+=1 i+=2 else: i+=1 m+=1 if i==n-1: m+=1 print(m)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(raw_input()) y=raw_input() i=0 r=n while i<n-1: if y[i]!=y[i+1]: r-=1 i+=1 i+=1 print r
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a = 0; vector<char> input(n); for (int i = 0; i < n; i++) cin >> input[i]; for (int i = 1; i < n; i++) { if (input[i] != input[i - 1]) { i++; a++; } } cout << n - a; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); string str, str2; cin >> str; for (int i(0); i < n; ++i) { if (str[i] == 'U' && str[i + 1] == 'R') { str2 += 'd'; str[i] = str[i + 1] = '1'; } else if (str[i] == 'R' && str[i + 1] == 'U') { str2 += 'd'...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0, i = 0; string s; cin >> n >> s; while (i < s.size()) { if (s[i] == 'U' && s[i + 1] == 'R') { c++; i += 2; } else if (s[i] == 'R' && s[i + 1] == 'U') { c++; i += 2; } else i++; } cout << s.size(...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() if n == 1: print(1) else: idx = 1 cnt = 0 while idx < n: if s[idx] != s[idx-1]: idx += 2 cnt += (1 if idx < n else 1 if idx > n else 2) else: idx += 1 cnt += (1 if idx < n else 2) print(cnt)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
x=int(input()) p=list(input()) t=list() i=0 while i<x-1: if p[i]!=p[i+1]: t.append("D") i+=1 i+=1 print(x-len(t))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0; string s; cin >> n; cin >> s; for (int i = 0; i < n;) { if (s[i] == 'U' && s[i + 1] == 'R' || s[i] == 'R' && s[i + 1] == 'U') { cnt++; i = i + 2; } else { cnt++; i++; } } cout << cnt; return 0;...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
N=int(input()) #take the size Array=list(map(str,input().split()[:N])) s=''.join(Array) l = len(s) c=0 j=1 while j < l: if s[j-1] == s[j]: j=j+1 else: c=c+1 j=j+2 print(l-c)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int n, ans; string s; int main() { cin >> n >> s; ans = n; for (int i = 1; i < n; i++) { if (s[i] == 'R' && s[i - 1] == 'U') { ans--; i++; } else if (s[i] == 'U' && s[i - 1] == 'R') { ans--; i++; } } cout << ans; return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; char a[maxn]; int main() { int n; cin >> n >> a; int len = strlen(a); for (int i = 1; i < len; ++i) { if ((a[i - 1] == 'R' && a[i] == 'U') || (a[i - 1] == 'U' && a[i] == 'R')) { i++; n--; } } cout << n << endl; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() a = '' for i in s: if len(a) == 0 or a[-1] == 'D' or a[-1] == i: a = a + i else: a = a[:-1] + 'D' print(len(a))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import sys n = int(input()) s = input() s = s + '$' res = "" i = 0 while i<=n-1: if s[i]=='R' and s[i+1]=='U': res = res + 'D' i = i + 2 elif s[i]=='U' and s[i+1]=='R': res = res + 'D' i = i + 2 else: res = res + s[i] i = i + 1 print(len(res))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) l = list(input()) i = 0 while (i<=(len(l)-2)): if(l[i]!=l[i+1]): l = l[:i]+['D']+l[i+2:] i+=1 print(len(l))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#Diag n=int(input()) st=input() lenth=len(st) i=0 sokr=0 while i < (len(st)-1): if st[i:i+2] in ['UR','RU']: st=st[0:i]+st[i+2:] sokr+=1 continue i+=1 print(lenth-sokr)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() m = 0 i = 0 while i < n - 1: if s[i] != s[i+1]: m +=1 i +=2 else: i += 1 print(n - m)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; void debug(string S = "hello ! debug") { cout << S << endl; return; } template <class T> void printVector(vector<T> &V) { cout << endl; for (int i = 0; i < V.size(); ++i) { cout << V[i] << " "; } cout << endl; return; } long long int sizeOfSt(long long int...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int n, u, r, c; string a; int main() { cin >> n; cin >> a; int i = 0; while (i < n) { if (a[i] != a[i + 1]) { i += 2; c++; } else { i++; c++; } } cout << c; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.*; public class Main { public static void main(String argz[]) { Scanner inp=new Scanner(System.in); String s=new String(); int n=inp.nextInt(); s=inp.next(); char arr[]=s.toCharArray(); int a=s.length(); for(int i=0;i<(s.length()-1);i++) ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import os import sys debug = True if debug and os.path.exists("input.in"): input = open("input.in", "r").readline else: debug = False input = sys.stdin.readline def inp(): return (int(input())) def inlt(): return (list(map(int, input().split()))) def insr(): s = input() return s[:le...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import re print input()-len(re.findall('RU|UR',raw_input()))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = list(input()) length = 0 iGen = (i for i in range(0, n)) try: for i in iGen: if i < n - 1 and s[i] != s[i + 1]: next(iGen, None) length += 1 except StopIteration: pass print(length)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 1; bool prev = false; string s; cin >> n >> s; for (int i = 1; i < s.length(); i++) if (!(!prev && ((s[i] == 'R' && s[i - 1] == 'U') || (s[i] == 'U' && s[i - 1] == 'R')))) { c++; prev = false; } else ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.*; public class CF954A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.nextLine()); String s = sc.nextLine(); int count = 0; for(int i = 0; i < s.length() - 1; i++) { if(s.substring(i,i+2).equal...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = list(str(input())) d = 0 for i in range(n-1): if s[i] != s[i+1] and s[i] != "*": d += 1 s[i+1] = "*" print(n-d)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import re a= input() text=input() rep={"RU":"D","UR":"D"} rep = dict((re.escape(k), v) for k, v in rep.items()) pattern = re.compile("|".join(rep.keys())) text = pattern.sub(lambda m: rep[re.escape(m.group(0))], text) print(len(text))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int b = 0, i, j, n, m; cin >> n; char a[n + 5]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { if ((a[i] == 'U' && a[i + 1] == 'R') || (a[i] == 'R' && a[i + 1] == 'U')) { b++; i++; } } cout << n - b; ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
# your code goes here a = input() b = raw_input() c = 0 i = 0 while i < a-1: if (b[i] != b[i+1]): c +=1 i = i+1 i = i+1 print(a-c)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; public class Main { static InputReader in; static PrintWriter out; static long time_start; static int cas = 0; static int mod = (int) 12357; static int inf = 0x3f3f3f3f; static long inff = 0x3f3f...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { string str; int l, c = 0; cin >> l >> str; for (int i = 0; i < (str.size() - 1); i++) { if (str[i] == 'U' && str[i + 1] == 'R') c++, i++; else if (str[i] == 'R' && str[i + 1] == 'U') c++, i++; } cout << l - c << endl; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.Scanner; public class Main { public static void main (String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); char[] in = sc.nextLine().toCharArray(); char prev = 'D'; int sub = 0; for(char curr : in){ if(prev != 'D' && curr...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.IOException; import java.util.*; public class d { public static void main(String[] args) throws IOException { Scanner s = new Scanner(System.in); // BufferedReader s=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); String...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() i=1 ans=0 while i < n: if s[i]!=s[i-1]: ans+=1 i+=1 i+=1 print(n-ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(raw_input()) s = raw_input() i = 0 cnt = 0 while i < n: cnt += 1 if s[i:i+2] in ('RU', 'UR'): i += 2 else: i += 1 print cnt
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) arr = input() count = n i = 0 while i < n - 1: if arr[i] != arr[i + 1]: count -= 1 i += 2 else: i += 1 print(count)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.*; import java.util.Random; public class Application { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); in.readLin...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() + "A" cnt = 0 i = 0 while i < n: if s[i] == "U" and s[i + 1] == "R": cnt += 1 i += 2 elif s[i] == "R" and s[i + 1] == "U": cnt += 1 i += 2 else: i += 1 print(n - cnt)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() l = 0 i = len(s) while i>=1: if (s[i-1] == "U" and s[i -2] == "R") or (s[i-1] == "R" and s[i -2] == "U"): i = i -2 l = l + 1 else: i = i -1 l = l + 1 print(l)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int count = 0; for (int i = 0; i < s.size() - 1; i++) { if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) { count++; i += 1; } } cout << s.size() - count; return ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.*; import java.util.*; public class Codeforces { public static long log2(long x) { long p=1; long ans=0; while(x>=p) { p*=2; ans++; } return ans-1; } public sta...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) a = input() i,c =0,0 while i<=n: if a[i:i+2] =="RU" or a[i:i+2]=="UR": c+=1 i+=2 else: i+=1 print(n-c)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#!/usr/bin/env python N = int(input()) indat = list(input().strip()) sw = 0 ans = 0 for s in indat: if sw == 0: tmp = s sw = 1 elif sw == 1: if s == tmp: ans += 1 else: sw = 0 tmp = 'D' ans += 1 if tmp != 'D': ans += 1 print(a...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
numOfChar = int(input()) stringOfMov = input() changedMov = list(stringOfMov) if numOfChar>1: item = 0 while (item < numOfChar - 1): if changedMov[item] == 'U' and changedMov[item+1] == 'R': if item > 1: if not(stringOfMov[item-2] == 'R' and stringOfMov[-1] == 'U'): ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() short_s = '' i = 0 while i < n: if s[i:i+2] == 'RU' or s[i:i+2] == 'UR': short_s += 'D' i += 2 else: short_s += s[i] i += 1 print(len(short_s))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int cnt, n; string ss; int main() { cin >> n >> ss; for (int i = 0; i < n; i++) { if (i < n - 1 && ((ss[i] == 'R' && ss[i + 1] == 'U') || (ss[i] == 'U' && ss[i + 1] == 'R'))) { i++; cnt++; } else cnt++; } cout << cnt <...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() ans = 0 tmp = 0 for i in range(n): ans+=1 if tmp == 0 and i > 0: if tmp == 0 and s[i] != s[i-1]: ans-=1 tmp = 1 else: tmp = 0 print(ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; string s; int main() { int n; cin >> n >> s; int res = 0; for (long long i = (long long)(0); i < (long long)(n); i++) { if (i < n - 1 && ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R'))) i++; res++; } cout << res << en...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q, k1, k2, k3, a, b, c; string s; while (cin >> n) { cin >> s; int ans = 0; for (int i = 1; i < s.length(); i++) if (s[i - 1] != s[i]) ans++, i++; cout << n - ans << endl; } return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k; int n, m; string s; cin >> n; cin >> s; int c = 0; for (i = 0; i < n - 1; i++) { if (i + 1 < n) { if (s[i] == 'U' && s[i + 1] == 'R') c++, i++; else if (s[i] == 'R' && s[i + 1] == 'U') c++, i++; } ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class StringRUD { public static void main(String[] args) throws NumberFormatException, IOException { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(Sy...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() count = len(s) i = 1 while i < len(s): if (s[i] == "U" and s[i - 1] == "R") or (s[i] == "R" and s[i - 1] == "U"): count -= 1 i += 1 i += 1 print(count)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
from collections import deque, Counter, OrderedDict from heapq import nsmallest, nlargest from math import ceil,floor,log,log2,sqrt,gcd,factorial def binNumber(n,size=1): return bin(n)[2:].zfill(size) def iar(): return list(map(int,input().split())) def ini(): return int(input()) def isp(): return ma...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import re input() print(len(re.sub(r'UR|RU', 'D', input()))) # Made By Mostafa_Khaled
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; /** * Created by prituladima on 5/23/18. */ public class DiagonalWalking { private void solve() throws IOE...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() ans = n i=0 while(i<n-1): #print(s[i]+s[i+1]) if(s[i]+s[i+1]=="RU" or s[i]+s[i+1] == "UR"): ans -= 1 i+=1 i+=1 print(ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; string s, ans = ""; cin >> s; for (long long i = 0; i < n; i++) { if (s[i] == 'R' and s[i + 1] == 'U') { ans += 'D'; i++; } else if (s[i] == 'U' and s[i + 1] == 'R') { ans += 'D'; i++; } els...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<char> v; char x; while (n--) { cin >> x; if (v.size() > 0 && x != v[v.size() - 1] && (v[v.size() - 1] == 'U' || v[v.size() - 1] == 'R')) v[v.size() - 1] = 'D'; else v.push_back(x); } co...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { int n; cin >> n; string s; cin >> s; int count = 0; for (int i = 0; i < n - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'U' || s[i] == 'U' && s[i + 1] =...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.*; public class fran { public static void main(String... args) { Scanner kbd = new Scanner(System.in); int f = kbd.nextInt(); char[] line = kbd.next().toCharArray(); for (int m = 0; m < line.length - 1; m++) { if ((line[m] == 'U' && line[m + 1] == 'R') || line[m] == 'R' && line[m + 1] == ...