buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
#include <algorithm> #include <cstring> #include <iostream> using namespace std; int main() { int a[101], m, x, y; bool b; m = 0; memset(a, 0, sizeof(int) * 101); while (cin >> x >> y) { if (!x && !y) { if (a[1] & 1 && a[2] & 1) { for (int i = 3; i <= m; i++) { if (a[i] & 1) { b = false; break; } } } else { b = false; } if (b) cout << "OK" << endl; else cout << "NG" << endl; m = 0; memset(a, 0, sizeof(int) * 101); } else { m = max(m, max(x, y)); ++a[x]; ++a[y]; } } }
#include <algorithm> #include <cstring> #include <iostream> using namespace std; int main() { int a[101], m, x, y; bool b; m = 0; memset(a, 0, sizeof(int) * 101); while (cin >> x >> y) { if (!x && !y) { if (a[1] & 1 && a[2] & 1) { b = true; for (int i = 3; i <= m; i++) { if (a[i] & 1) { b = false; break; } } } else { b = false; } if (b) cout << "OK" << endl; else cout << "NG" << endl; m = 0; memset(a, 0, sizeof(int) * 101); } else { m = max(m, max(x, y)); ++a[x]; ++a[y]; } } }
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 146], ["+", 64, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
1
195
4
route = Array.new(100,0) readlines.each do |line| frm,to = line.split.map(&:to_i) if frm == 0 && to == 0 if route[1].odd? && route[2].odd? && route.drop(3).all?(&:even?) puts"OK" else puts"NG" end nodes = Array.new(100){0} else route[frm] +=1 route[to] +=1 end end
route = Array.new(100,0) readlines.each do |line| frm,to = line.split.map(&:to_i) if frm == 0 && to == 0 if route[1].odd? && route[2].odd? && route.drop(3).all?(&:even?) puts"OK" else puts"NG" end route = Array.new(100){0} else route[frm] +=1 route[to] +=1 end end
[["-", 8, 736, 0, 121, 64, 749, 0, 662, 31, 22], ["+", 8, 736, 0, 121, 64, 749, 0, 662, 31, 22]]
4
101
2
while true pts = [] while true line = gets exit if line.nil? p0, p1 = line.chomp.split(" ").map{|s| s.to_i} break if p0 == 0 && p1 == 0 p0 -= 1 p1 -= 1 pts[p0] = pts[p0].nil? ? 1 : (pts[p0] + 1) pts[p1] = pts[p1].nil? ? 1 : (pts[p1] + 1) end #p pts ok = true if pts[0] % 2 == 0 || pts[1] % 2 == 0 ok = false break end for i in (2...pts.length) if pts[i] % 2 != 0 ok = false break end end puts ok ? "OK" : "NG" end
while true pts = [] while true line = gets exit if line.nil? p0, p1 = line.chomp.split(" ").map{|s| s.to_i} break if p0 == 0 && p1 == 0 p0 -= 1 p1 -= 1 pts[p0] = pts[p0].nil? ? 1 : (pts[p0] + 1) pts[p1] = pts[p1].nil? ? 1 : (pts[p1] + 1) end #p pts ok = true if pts[0] % 2 == 0 || pts[1] % 2 == 0 ok = false else for i in (2...pts.length) if pts[i] % 2 != 0 ok = false break end end end puts ok ? "OK" : "NG" end
[["-", 8, 170, 0, 121, 64, 749, 0, 94, 0, 94], ["-", 0, 493, 0, 89, 8, 170, 0, 121, 0, 444], ["+", 0, 89, 8, 170, 0, 121, 75, 95, 0, 95], ["+", 75, 95, 0, 88, 8, 170, 0, 121, 0, 444]]
4
163
4
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { char ch[] = in.nextLine().toCharArray(); String st = ""; String ans = ""; for (int i = 0; i < ch.length; i++) { if (ch[i] == ' ') st += "101"; else if (ch[i] == '\'') st += "000000"; else if (ch[i] == ',') st += "000011"; else if (ch[i] == '-') st += "10010001"; else if (ch[i] == '.') st += "010001"; else if (ch[i] == '?') st += "000001"; else if (ch[i] == 'A') st += "000011"; else if (ch[i] == 'B') st += "10011010"; else if (ch[i] == 'C') st += "0101"; else if (ch[i] == 'D') st += "0001"; else if (ch[i] == 'E') st += "110"; else if (ch[i] == 'F') st += "01001"; else if (ch[i] == 'G') st += "10011011"; else if (ch[i] == 'H') st += "010000"; else if (ch[i] == 'I') st += "0111"; else if (ch[i] == 'J') st += "10011000"; else if (ch[i] == 'K') st += "0110"; else if (ch[i] == 'L') st += "00100"; else if (ch[i] == 'M') st += "10011001"; else if (ch[i] == 'N') st += "10011110"; else if (ch[i] == 'O') st += "00101"; else if (ch[i] == 'P') st += "111"; else if (ch[i] == 'Q') st += "10011111"; else if (ch[i] == 'R') st += "1000"; else if (ch[i] == 'S') st += "00110"; else if (ch[i] == 'T') st += "00111"; else if (ch[i] == 'U') st += "10011000"; else if (ch[i] == 'V') st += "10011001"; else if (ch[i] == 'W') st += "000010"; else if (ch[i] == 'X') st += "10010010"; else if (ch[i] == 'Y') st += "10010011"; else if (ch[i] == 'Z') st += "10010000"; } while (st.length() % 5 != 0) st += "0"; while (st.length() > 0) { String tmp = st.substring(0, 5); st = st.substring(5, st.length()); if (tmp.equals("00000")) ans += "A"; else if (tmp.equals("00001")) ans += "B"; else if (tmp.equals("00010")) ans += "C"; else if (tmp.equals("00011")) ans += "D"; else if (tmp.equals("00100")) ans += "E"; else if (tmp.equals("00101")) ans += "F"; else if (tmp.equals("00110")) ans += "G"; else if (tmp.equals("00111")) ans += "H"; else if (tmp.equals("01000")) ans += "I"; else if (tmp.equals("01001")) ans += "J"; else if (tmp.equals("01010")) ans += "K"; else if (tmp.equals("01011")) ans += "L"; else if (tmp.equals("01100")) ans += "M"; else if (tmp.equals("01101")) ans += "N"; else if (tmp.equals("01110")) ans += "O"; else if (tmp.equals("01111")) ans += "P"; else if (tmp.equals("10000")) ans += "Q"; else if (tmp.equals("10001")) ans += "R"; else if (tmp.equals("10010")) ans += "S"; else if (tmp.equals("10011")) ans += "T"; else if (tmp.equals("10100")) ans += "U"; else if (tmp.equals("10101")) ans += "V"; else if (tmp.equals("10110")) ans += "W"; else if (tmp.equals("10111")) ans += "X"; else if (tmp.equals("11000")) ans += "Y"; else if (tmp.equals("11001")) ans += "Z"; else if (tmp.equals("11010")) ans += " "; else if (tmp.equals("11011")) ans += "."; else if (tmp.equals("11100")) ans += ","; else if (tmp.equals("11101")) ans += "-"; else if (tmp.equals("11110")) ans += "'"; else if (tmp.equals("11111")) ans += "?"; } System.out.println(ans); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { char ch[] = in.nextLine().toCharArray(); String st = ""; String ans = ""; for (int i = 0; i < ch.length; i++) { if (ch[i] == ' ') st += "101"; else if (ch[i] == '\'') st += "000000"; else if (ch[i] == ',') st += "000011"; else if (ch[i] == '-') st += "10010001"; else if (ch[i] == '.') st += "010001"; else if (ch[i] == '?') st += "000001"; else if (ch[i] == 'A') st += "100101"; else if (ch[i] == 'B') st += "10011010"; else if (ch[i] == 'C') st += "0101"; else if (ch[i] == 'D') st += "0001"; else if (ch[i] == 'E') st += "110"; else if (ch[i] == 'F') st += "01001"; else if (ch[i] == 'G') st += "10011011"; else if (ch[i] == 'H') st += "010000"; else if (ch[i] == 'I') st += "0111"; else if (ch[i] == 'J') st += "10011000"; else if (ch[i] == 'K') st += "0110"; else if (ch[i] == 'L') st += "00100"; else if (ch[i] == 'M') st += "10011001"; else if (ch[i] == 'N') st += "10011110"; else if (ch[i] == 'O') st += "00101"; else if (ch[i] == 'P') st += "111"; else if (ch[i] == 'Q') st += "10011111"; else if (ch[i] == 'R') st += "1000"; else if (ch[i] == 'S') st += "00110"; else if (ch[i] == 'T') st += "00111"; else if (ch[i] == 'U') st += "10011100"; else if (ch[i] == 'V') st += "10011101"; else if (ch[i] == 'W') st += "000010"; else if (ch[i] == 'X') st += "10010010"; else if (ch[i] == 'Y') st += "10010011"; else if (ch[i] == 'Z') st += "10010000"; } while (st.length() % 5 != 0) st += "0"; while (st.length() > 0) { String tmp = st.substring(0, 5); st = st.substring(5, st.length()); if (tmp.equals("00000")) ans += "A"; else if (tmp.equals("00001")) ans += "B"; else if (tmp.equals("00010")) ans += "C"; else if (tmp.equals("00011")) ans += "D"; else if (tmp.equals("00100")) ans += "E"; else if (tmp.equals("00101")) ans += "F"; else if (tmp.equals("00110")) ans += "G"; else if (tmp.equals("00111")) ans += "H"; else if (tmp.equals("01000")) ans += "I"; else if (tmp.equals("01001")) ans += "J"; else if (tmp.equals("01010")) ans += "K"; else if (tmp.equals("01011")) ans += "L"; else if (tmp.equals("01100")) ans += "M"; else if (tmp.equals("01101")) ans += "N"; else if (tmp.equals("01110")) ans += "O"; else if (tmp.equals("01111")) ans += "P"; else if (tmp.equals("10000")) ans += "Q"; else if (tmp.equals("10001")) ans += "R"; else if (tmp.equals("10010")) ans += "S"; else if (tmp.equals("10011")) ans += "T"; else if (tmp.equals("10100")) ans += "U"; else if (tmp.equals("10101")) ans += "V"; else if (tmp.equals("10110")) ans += "W"; else if (tmp.equals("10111")) ans += "X"; else if (tmp.equals("11000")) ans += "Y"; else if (tmp.equals("11001")) ans += "Z"; else if (tmp.equals("11010")) ans += " "; else if (tmp.equals("11011")) ans += "."; else if (tmp.equals("11100")) ans += ","; else if (tmp.equals("11101")) ans += "-"; else if (tmp.equals("11110")) ans += "'"; else if (tmp.equals("11111")) ans += "?"; } System.out.println(ans); } } }
[["-", 75, 57, 64, 1, 0, 11, 12, 5, 0, 491], ["+", 75, 57, 64, 1, 0, 11, 12, 5, 0, 491]]
3
1,242
6
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) throws IOException { Main instance = new Main(); instance.execute(); } private void execute() throws IOException { BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); Map<String, String> encriptMap = getEncriptMap(); Map<String, String> decriptMap = getDecriptMap(); StringBuilder sb; StringBuilder result; String line; while ((line = sc.readLine()) != null) { sb = new StringBuilder(); for (int i = 0; i < line.length(); i++) { sb.append(encriptMap.get(line.substring(i, i + 1))); } while (sb.length() % 5 > 0) { sb.append("0"); } result = new StringBuilder(); for (int i = 0; i < sb.length(); i = i + 5) { result.append(decriptMap.get(sb.substring(i, i + 5))); } System.out.println(result.toString()); } } private Map<String, String> getEncriptMap() { Map<String, String> map = new HashMap<String, String>(); map.put(" ", "101"); map.put("'", "000000"); map.put(",", "000011"); map.put("-", "10010001"); map.put(".", "010001"); map.put("?", "000001"); map.put("A", "100101"); map.put("B", "10011010"); map.put("C", "0101"); map.put("D", "0001"); map.put("E", "110"); map.put("F", "01001"); map.put("G", "10011011"); map.put("H", "010000"); map.put("I", "0111"); map.put("J", "10011000"); map.put("K", "0110"); map.put("L", "00100"); map.put("M", "10011001"); map.put("N", "10011110"); map.put("O", "00101"); map.put("P", "111"); map.put("Q", "10011111"); map.put("R", "1000"); map.put("S", "00110"); map.put("T", "00111"); map.put("U", "10011100"); map.put("V", "10011101"); map.put("W", "000010"); map.put("X", "10010010"); map.put("Y", "10010011"); map.put("Z", "10010000"); return map; } private Map<String, String> getDecriptMap() { Map<String, String> map = new HashMap<String, String>(); map.put("00000", "A"); map.put("00001", "B"); map.put("00010", "C"); map.put("00011", "D"); map.put("00100", "E"); map.put("00101", "F"); map.put("00110", "G"); map.put("00111", "H"); map.put("01000", "I"); map.put("01001", "J"); map.put("01010", "K"); map.put("01011", "L"); map.put("01100", "M"); map.put("01101", "N"); map.put("01110", "O"); map.put("01111", "P"); map.put("10000", "Q"); map.put("10001", "R"); map.put("10010", "S"); map.put("10011", "T"); map.put("10100", "U"); map.put("10101", "V"); map.put("10110", "W"); map.put("10111", "X"); map.put("11000", "Y"); map.put("11001", "Z"); map.put("11010", " "); map.put("11011", "."); map.put("11100", ","); map.put("11101", "-"); map.put("11110", ""); map.put("11111", "?"); return map; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) throws IOException { Main instance = new Main(); instance.execute(); } private void execute() throws IOException { BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); Map<String, String> encriptMap = getEncriptMap(); Map<String, String> decriptMap = getDecriptMap(); StringBuilder sb; StringBuilder result; String line; while ((line = sc.readLine()) != null) { sb = new StringBuilder(); for (int i = 0; i < line.length(); i++) { sb.append(encriptMap.get(line.substring(i, i + 1))); } while (sb.length() % 5 > 0) { sb.append("0"); } result = new StringBuilder(); for (int i = 0; i < sb.length(); i = i + 5) { result.append(decriptMap.get(sb.substring(i, i + 5))); } System.out.println(result.toString()); } } private Map<String, String> getEncriptMap() { Map<String, String> map = new HashMap<String, String>(); map.put(" ", "101"); map.put("'", "000000"); map.put(",", "000011"); map.put("-", "10010001"); map.put(".", "010001"); map.put("?", "000001"); map.put("A", "100101"); map.put("B", "10011010"); map.put("C", "0101"); map.put("D", "0001"); map.put("E", "110"); map.put("F", "01001"); map.put("G", "10011011"); map.put("H", "010000"); map.put("I", "0111"); map.put("J", "10011000"); map.put("K", "0110"); map.put("L", "00100"); map.put("M", "10011001"); map.put("N", "10011110"); map.put("O", "00101"); map.put("P", "111"); map.put("Q", "10011111"); map.put("R", "1000"); map.put("S", "00110"); map.put("T", "00111"); map.put("U", "10011100"); map.put("V", "10011101"); map.put("W", "000010"); map.put("X", "10010010"); map.put("Y", "10010011"); map.put("Z", "10010000"); return map; } private Map<String, String> getDecriptMap() { Map<String, String> map = new HashMap<String, String>(); map.put("00000", "A"); map.put("00001", "B"); map.put("00010", "C"); map.put("00011", "D"); map.put("00100", "E"); map.put("00101", "F"); map.put("00110", "G"); map.put("00111", "H"); map.put("01000", "I"); map.put("01001", "J"); map.put("01010", "K"); map.put("01011", "L"); map.put("01100", "M"); map.put("01101", "N"); map.put("01110", "O"); map.put("01111", "P"); map.put("10000", "Q"); map.put("10001", "R"); map.put("10010", "S"); map.put("10011", "T"); map.put("10100", "U"); map.put("10101", "V"); map.put("10110", "W"); map.put("10111", "X"); map.put("11000", "Y"); map.put("11001", "Z"); map.put("11010", " "); map.put("11011", "."); map.put("11100", ","); map.put("11101", "-"); map.put("11110", "'"); map.put("11111", "?"); return map; } }
[["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
3
1,173
1
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { private static BufferedReader br = null; static { br = new BufferedReader(new InputStreamReader(System.in)); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String stdin = null; while ((stdin = parseStdin()) != null) { String work = ""; String out = ""; for (int loop = 0; loop < stdin.length(); loop++) { work += MyConv.Encode(stdin.charAt(loop)); } while (work.length() % 5 != 0) { work += "0"; } for (int loop = 0; loop < stdin.length(); loop += 5) { out += MyConv.Decode(work.substring(loop, loop + 5)); } System.out.println(out); } } private static String parseStdin() { String stdin = null; try { stdin = br.readLine(); } catch (IOException e) { } return stdin; } } class MyConv { public static String Encode(char key) { switch (key) { case ' ': return "101"; case '\'': return "000000"; case ',': return "000011"; case '-': return "10010001"; case '.': return "010001"; case '?': return "000001"; case 'A': return "100101"; case 'B': return "10011010"; case 'C': return "0101"; case 'D': return "0001"; case 'E': return "110"; case 'F': return "01001"; case 'G': return "10011011"; case 'H': return "010000"; case 'I': return "0111"; case 'J': return "10011000"; case 'K': return "0110"; case 'L': return "00100"; case 'M': return "10011001"; case 'N': return "10011110"; case 'O': return "00101"; case 'P': return "111"; case 'Q': return "10011111"; case 'R': return "1000"; case 'S': return "00110"; case 'T': return "00111"; case 'U': return "10011100"; case 'V': return "10011101"; case 'W': return "000010"; case 'X': return "10010010"; case 'Y': return "10010011"; case 'Z': return "10010000"; } return ""; } public static char Decode(String key) { if (key.equals("00000")) return 'A'; if (key.equals("00001")) return 'B'; if (key.equals("00010")) return 'C'; if (key.equals("00011")) return 'D'; if (key.equals("00100")) return 'E'; if (key.equals("00101")) return 'F'; if (key.equals("00110")) return 'G'; if (key.equals("00111")) return 'H'; if (key.equals("01000")) return 'I'; if (key.equals("01001")) return 'J'; if (key.equals("01010")) return 'K'; if (key.equals("01011")) return 'L'; if (key.equals("01100")) return 'M'; if (key.equals("01101")) return 'N'; if (key.equals("01110")) return 'O'; if (key.equals("01111")) return 'P'; if (key.equals("10000")) return 'Q'; if (key.equals("10001")) return 'R'; if (key.equals("10010")) return 'S'; if (key.equals("10011")) return 'T'; if (key.equals("10100")) return 'U'; if (key.equals("10101")) return 'V'; if (key.equals("10110")) return 'W'; if (key.equals("10111")) return 'X'; if (key.equals("11000")) return 'Y'; if (key.equals("11001")) return 'Z'; if (key.equals("11010")) return ' '; if (key.equals("11011")) return '.'; if (key.equals("11100")) return ','; if (key.equals("11101")) return '-'; if (key.equals("11110")) return '\''; if (key.equals("11111")) return '?'; return 0; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { private static BufferedReader br = null; static { br = new BufferedReader(new InputStreamReader(System.in)); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String stdin = null; while ((stdin = parseStdin()) != null) { String work = ""; String out = ""; for (int loop = 0; loop < stdin.length(); loop++) { work += MyConv.Encode(stdin.charAt(loop)); } while (work.length() % 5 != 0) { work += "0"; } for (int loop = 0; loop < work.length(); loop += 5) { out += MyConv.Decode(work.substring(loop, loop + 5)); } System.out.println(out); } } private static String parseStdin() { String stdin = null; try { stdin = br.readLine(); } catch (IOException e) { } return stdin; } } class MyConv { public static String Encode(char key) { switch (key) { case ' ': return "101"; case '\'': return "000000"; case ',': return "000011"; case '-': return "10010001"; case '.': return "010001"; case '?': return "000001"; case 'A': return "100101"; case 'B': return "10011010"; case 'C': return "0101"; case 'D': return "0001"; case 'E': return "110"; case 'F': return "01001"; case 'G': return "10011011"; case 'H': return "010000"; case 'I': return "0111"; case 'J': return "10011000"; case 'K': return "0110"; case 'L': return "00100"; case 'M': return "10011001"; case 'N': return "10011110"; case 'O': return "00101"; case 'P': return "111"; case 'Q': return "10011111"; case 'R': return "1000"; case 'S': return "00110"; case 'T': return "00111"; case 'U': return "10011100"; case 'V': return "10011101"; case 'W': return "000010"; case 'X': return "10010010"; case 'Y': return "10010011"; case 'Z': return "10010000"; } return ""; } public static char Decode(String key) { if (key.equals("00000")) return 'A'; if (key.equals("00001")) return 'B'; if (key.equals("00010")) return 'C'; if (key.equals("00011")) return 'D'; if (key.equals("00100")) return 'E'; if (key.equals("00101")) return 'F'; if (key.equals("00110")) return 'G'; if (key.equals("00111")) return 'H'; if (key.equals("01000")) return 'I'; if (key.equals("01001")) return 'J'; if (key.equals("01010")) return 'K'; if (key.equals("01011")) return 'L'; if (key.equals("01100")) return 'M'; if (key.equals("01101")) return 'N'; if (key.equals("01110")) return 'O'; if (key.equals("01111")) return 'P'; if (key.equals("10000")) return 'Q'; if (key.equals("10001")) return 'R'; if (key.equals("10010")) return 'S'; if (key.equals("10011")) return 'T'; if (key.equals("10100")) return 'U'; if (key.equals("10101")) return 'V'; if (key.equals("10110")) return 'W'; if (key.equals("10111")) return 'X'; if (key.equals("11000")) return 'Y'; if (key.equals("11001")) return 'Z'; if (key.equals("11010")) return ' '; if (key.equals("11011")) return '.'; if (key.equals("11100")) return ','; if (key.equals("11101")) return '-'; if (key.equals("11110")) return '\''; if (key.equals("11111")) return '?'; return 0; } }
[["-", 8, 196, 0, 7, 15, 16, 12, 492, 500, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 492, 500, 22]]
3
972
2
#include <stdio.h> #include <string.h> int main() { char c[] = {" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"}; char w[][9] = {"101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "01010", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "1001111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"}; char n[102]; // char s[920]={0}; int i, j; while (fgets(n, 101, stdin) != NULL) { char s[920] = {0}; for (i = 0; n[i + 1]; i++) { for (j = 0; n[i] != c[j]; j++) ; strcat(s, w[j]); } // printf("%s\n",s); for (i = j = 0; s[i]; i++) { j *= 2; if (s[i] == '1') j++; if (i % 5 == 4) { printf("%c", c[j + 6]); j = 0; } } if (i % 5) { for (; i % 5 != 0; i++) j *= 2; printf("%c", c[j + 6]); } printf("\n"); } return 0; }
#include <stdio.h> #include <string.h> int main() { char c[] = {" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"}; char w[][9] = {"101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"}; char n[102]; // char s[920]={0}; int i, j; while (fgets(n, 101, stdin) != NULL) { char s[920] = {0}; for (i = 0; n[i + 1]; i++) { for (j = 0; n[i] != c[j]; j++) ; strcat(s, w[j]); } // printf("%s\n",s); for (i = j = 0; s[i]; i++) { j *= 2; if (s[i] == '1') j++; if (i % 5 == 4) { printf("%c", c[j + 6]); j = 0; } } if (i % 5) { for (; i % 5 != 0; i++) j *= 2; printf("%c", c[j + 6]); } printf("\n"); } return 0; }
[["-", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6], ["+", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6]]
0
357
4
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char str[200] = "", code[100000] = ""; char *pstr, *pcode; int x, b, base; while (fgets(str, sizeof(str), stdin) != NULL) { pstr = &str[0]; pcode = &code[0]; while (*pstr) { switch (*pstr) { case 'O': strcat(pcode, "0"); case 'C': strcat(pcode, "0"); case ' ': strcat(pcode, "101"); break; case '\'': strcat(pcode, "000000"); break; case ',': strcat(pcode, "000011"); break; case '-': strcat(pcode, "1001"); case 'D': strcat(pcode, "0001"); break; case '.': strcat(pcode, "010001"); break; case 'T': strcat(pcode, "0"); case 'I': strcat(pcode, "0"); case 'P': strcat(pcode, "111"); break; case 'S': strcat(pcode, "0"); case 'K': strcat(pcode, "0"); case 'E': strcat(pcode, "110"); break; case 'A': strcat(pcode, "100101"); break; case 'B': strcat(pcode, "10011010"); break; case 'F': strcat(pcode, "01001"); break; case 'G': strcat(pcode, "10011011"); break; case 'H': strcat(pcode, "010000"); break; case 'J': strcat(pcode, "1001"); case 'R': strcat(pcode, "1000"); break; case 'L': strcat(pcode, "00100"); break; case 'M': strcat(pcode, "10011001"); break; case 'N': strcat(pcode, "10011110"); break; case 'Q': strcat(pcode, "1001111"); break; case 'U': strcat(pcode, "10011100"); break; case 'V': strcat(pcode, "10011101"); break; case 'W': strcat(pcode, "000010"); break; case 'X': strcat(pcode, "10010011"); break; case 'Y': strcat(pcode, "10010011"); break; case 'Z': strcat(pcode, "10010000"); break; case '?': strcat(pcode, "000001"); break; default: break; } pstr++; } while (strlen(pcode) % 5) strcat(pcode, "0"); while (*pcode) { sprintf(str, "%.5s", pcode); pcode += 5; b = atoi(str); base = 1, x = 0; while (b > 0) { x += (b % 10) * base; b /= 10; base *= 2; } if (x == 26) x = ' ' - 'A'; else if (x == 27) x = '.' - 'A'; else if (x == 28) x = ',' - 'A'; else if (x == 29) x = '-' - 'A'; else if (x == 30) x = '\'' - 'A'; else if (x == 31) x = '?' - 'A'; printf("%c", 'A' + x); } printf("\n"); memset(code, '\0', sizeof(code)); memset(str, '\0', sizeof(str)); } return 0; }
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char str[200] = "", code[100000] = ""; char *pstr, *pcode; int x, b, base; while (fgets(str, sizeof(str), stdin) != NULL) { pstr = &str[0]; pcode = &code[0]; while (*pstr) { switch (*pstr) { case 'O': strcat(pcode, "0"); case 'C': strcat(pcode, "0"); case ' ': strcat(pcode, "101"); break; case '\'': strcat(pcode, "000000"); break; case ',': strcat(pcode, "000011"); break; case '-': strcat(pcode, "1001"); case 'D': strcat(pcode, "0001"); break; case '.': strcat(pcode, "010001"); break; case 'T': strcat(pcode, "0"); case 'I': strcat(pcode, "0"); case 'P': strcat(pcode, "111"); break; case 'S': strcat(pcode, "0"); case 'K': strcat(pcode, "0"); case 'E': strcat(pcode, "110"); break; case 'A': strcat(pcode, "100101"); break; case 'B': strcat(pcode, "10011010"); break; case 'F': strcat(pcode, "01001"); break; case 'G': strcat(pcode, "10011011"); break; case 'H': strcat(pcode, "010000"); break; case 'J': strcat(pcode, "1001"); case 'R': strcat(pcode, "1000"); break; case 'L': strcat(pcode, "00100"); break; case 'M': strcat(pcode, "10011001"); break; case 'N': strcat(pcode, "10011110"); break; case 'Q': strcat(pcode, "10011111"); break; case 'U': strcat(pcode, "10011100"); break; case 'V': strcat(pcode, "10011101"); break; case 'W': strcat(pcode, "000010"); break; case 'X': strcat(pcode, "10010010"); break; case 'Y': strcat(pcode, "10010011"); break; case 'Z': strcat(pcode, "10010000"); break; case '?': strcat(pcode, "000001"); break; default: break; } pstr++; } while (strlen(pcode) % 5) strcat(pcode, "0"); while (*pcode) { sprintf(str, "%.5s", pcode); pcode += 5; b = atoi(str); base = 1, x = 0; while (b > 0) { x += (b % 10) * base; b /= 10; base *= 2; } if (x == 26) x = ' ' - 'A'; else if (x == 27) x = '.' - 'A'; else if (x == 28) x = ',' - 'A'; else if (x == 29) x = '-' - 'A'; else if (x == 30) x = '\'' - 'A'; else if (x == 31) x = '?' - 'A'; printf("%c", 'A' + x); } printf("\n"); memset(code, '\0', sizeof(code)); memset(str, '\0', sizeof(str)); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
831
4
char *C = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?", *strchr(), *L = "68443586484588538455886888366866"; char B[] = {0x25, 0x9a, 0x05, 0x01, 0x06, 0x09, 0x9b, 0x10, 0x07, 0x98, 0x06, 0x04, 0x99, 0x9e, 0x05, 0x07, 0x9f, 0x08, 0x06, 0x07, 0x9c, 0x9d, 0x02, 0x92, 0x93, 0x90, 0x05, 0x11, 0x03, 0x91, 0x00, 0x01}; b, l; main(c) { for (; c = getchar(), c + 1;) if (c - 10) for (c = strchr(C, c) - C, b = b << L[c] - 48 | B[c], l += L[c] - 48; l > 4; putchar(C[b >> l & 31])) l -= 5; else l &&putchar(C[(b <<= 5 - l) & 31]), l = 0, putchar(c); exit(0); }
char *C = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?", *strchr(), *L = "68443586484588538455886888366866"; B[] = {0x25, 0x9a, 0x05, 0x01, 0x06, 0x09, 0x9b, 0x10, 0x07, 0x98, 0x06, 0x04, 0x99, 0x9e, 0x05, 0x07, 0x9f, 0x08, 0x06, 0x07, 0x9c, 0x9d, 0x02, 0x92, 0x93, 0x90, 0x05, 0x11, 0x03, 0x91, 0x00, 0x01}; b, l; main(c) { for (; c = getchar(), c + 1;) if (c - 10) for (c = strchr(C, c) - C, b = b << (L[c] - 48) | B[c], l += L[c] - 48; l > 4; putchar(C[b >> l & 31])) l -= 5; else l &&putchar(C[(b <<= 5 - l) & 31]), l = 0, putchar(c); exit(0); }
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 0, 30, 0, 42, 0, 69, 0, 70, 0, 22], ["+", 31, 11, 12, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 11, 12, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 9, 0, 14, 8, 9, 0, 46, 0, 46]]
0
212
5
char *C = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?", *strchr(), *L = "68443586484588538455886888366866"; char B[] = {0x25, 0x9a, 0x05, 0x01, 0x06, 0x09, 0x9b, 0x10, 0x07, 0x98, 0x06, 0x04, 0x99, 0x9e, 0x05, 0x07, 0x9f, 0x08, 0x06, 0x07, 0x9c, 0x9d, 0x02, 0x92, 0x93, 0x90, 0x05, 0x11, 0x03, 0x91, 0x00, 0x01}; b, l; main(c) { for (; c = getchar(), c + 1;) if (c - 10) for (c = strchr(C, c) - C, b = b << (L[c] - 48) | B[c], l += L[c] - 48; l > 4; putchar(C[b >> l & 31])) l -= 5; else l &&putchar(C[(b <<= 5 - l) & 31]), l = 0, putchar(c); exit(0); }
char *C = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?", *strchr(), *L = "68443586484588538455886888366866"; unsigned char B[] = {0x25, 0x9a, 0x05, 0x01, 0x06, 0x09, 0x9b, 0x10, 0x07, 0x98, 0x06, 0x04, 0x99, 0x9e, 0x05, 0x07, 0x9f, 0x08, 0x06, 0x07, 0x9c, 0x9d, 0x02, 0x92, 0x93, 0x90, 0x05, 0x11, 0x03, 0x91, 0x00, 0x01}; b, l; main(c) { for (; c = getchar(), c + 1;) if (c - 10) for (c = strchr(C, c) - C, b = b << (L[c] - 48) | B[c], l += L[c] - 48; l > 4; putchar(C[b >> l & 31])) l -= 5; else l &&putchar(C[(b <<= 5 - l) & 31]), l = 0, putchar(c); exit(0); }
[["+", 36, 36, 0, 30, 0, 43, 39, 86, 0, 87]]
0
214
1
/* AizuOnline A0088 The Code A Doctor Loved */ #include <stdio.h> // Select Below //#include <stdlib.h> #include <string.h> //#include <float.h> //#include <math.h> // Global data section char heibun[1000]; char s1[10000]; char s2[2000]; char *step1table[] = { // SP ' , - . ? "101", "000000", "000011", "10010001", "010001", "000001", // A-B "100101", "10011010", // C-J "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", // K-R "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", // S-Z "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"}; int conv(char c) { // printf("%c",c); char *x; char compared[] = " ',-.?"; if (NULL != (x = strchr(compared, c))) return (x - compared); return (c - 'A' + 6); } void step1() { char *s, c; s = heibun; s1[0] = '\0'; while (c = *s++) { // printf("%c %s\n",c,step1table[conv(c)]); strcat(s1, step1table[conv(c)]); } strcat(s1, "0000"); } int conv5bin(char *s) { // printf("%5s\n",s); int sum; sum = (s[0] == '1') ? 16 : 0; sum += (s[1] == '1') ? 8 : 0; sum += (s[2] == '1') ? 4 : 0; sum += (s[3] == '1') ? 2 : 0; sum += (s[4] == '1') ? 1 : 0; return (sum); } void step2() { int s2ptr; int i; s2ptr = 0; for (i = 0; i < strlen(s1); i += 5) s2[s2ptr++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[conv5bin(&(s1[i]))]; s2ptr = '\0'; } main() { int i; while (NULL != gets(heibun)) { for (i = 0; i < 2000; i++) s2[i] = '\0'; step1(); step2(); // printf("%s\n",s1); printf("%s\n", s2); } return (0); }
/* AizuOnline A0088 The Code A Doctor Loved 2012/12/31 WA */ #include <stdio.h> // Select Below //#include <stdlib.h> #include <string.h> //#include <float.h> //#include <math.h> // Global data section char heibun[1000]; char s1[10000]; char s2[2000]; char *step1table[] = { // SP ' , - . ? "101", "000000", "000011", "10010001", "010001", "000001", // A-B "100101", "10011010", // C-J "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", // K-R "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", // S-Z "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"}; int conv(char c) { // printf("%c",c); char *x; char compared[] = " ',-.?"; if (NULL != (x = strchr(compared, c))) return (x - compared); return (c - 'A' + 6); } void step1() { char *s, c; s = heibun; s1[0] = '\0'; while (c = *s++) { // printf("%c %s\n",c,step1table[conv(c)]); strcat(s1, step1table[conv(c)]); } strcat(s1, "0000"); } int conv5bin(char *s) { // printf("%5s\n",s); int sum; sum = (s[0] == '1') ? 16 : 0; sum += (s[1] == '1') ? 8 : 0; sum += (s[2] == '1') ? 4 : 0; sum += (s[3] == '1') ? 2 : 0; sum += (s[4] == '1') ? 1 : 0; return (sum); } void step2() { int s2ptr; int i; s2ptr = 0; for (i = 0; i < (strlen(s1) / 5) * 5; i += 5) s2[s2ptr++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"[conv5bin(&(s1[i]))]; s2ptr = '\0'; } main() { int i; while (NULL != gets(heibun)) { for (i = 0; i < 2000; i++) s2[i] = '\0'; step1(); step2(); // printf("%s\n",s1); printf("%s\n", s2); } return (0); }
[["+", 0, 7, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 2, 3, 4, 0, 25], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 85], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 48], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
0
512
6
#include <stdio.h> #include <string.h> char encode[96][8]; char decode[32]; int main(void) { strcpy(encode[' '], "101"); strcpy(encode['\n'], ""); strcpy(encode['\''], "000000"); strcpy(encode[','], "000011"); strcpy(encode['-'], "10010001"); strcpy(encode['.'], "010001"); strcpy(encode['?'], "000001"); strcpy(encode['A'], "100101"); strcpy(encode['B'], "10011010"); strcpy(encode['C'], "0101"); strcpy(encode['D'], "0001"); strcpy(encode['E'], "110"); strcpy(encode['F'], "01001"); strcpy(encode['G'], "10011011"); strcpy(encode['H'], "010000"); strcpy(encode['I'], "0111"); strcpy(encode['J'], "10011000"); strcpy(encode['K'], "0110"); strcpy(encode['L'], "00100"); strcpy(encode['M'], "10011001"); strcpy(encode['N'], "10011110"); strcpy(encode['O'], "00101"); strcpy(encode['P'], "111"); strcpy(encode['Q'], "10011111"); strcpy(encode['R'], "1000"); strcpy(encode['S'], "00110"); strcpy(encode['T'], "00111"); strcpy(encode['U'], "10011100"); strcpy(encode['V'], "10011101"); strcpy(encode['W'], "000010"); strcpy(encode['X'], "10010010"); strcpy(encode['Y'], "10010011"); strcpy(encode['Z'], "10010000"); int n, i, k; char type[200], code[10000]; for (i = 0; i < 26; i++) { decode[i] = 'A' + i; } decode[26] = ' '; decode[27] = '.'; decode[28] = ','; decode[29] = '-'; decode[30] = '\''; decode[31] = '?'; while (fgets(type, 10000, stdin) != NULL) { code[0] = '\0'; n = strlen(type); for (i = 0; i < n; i++) { strcat(code, encode[type[i]]); } n = strlen(code); for (i = 0; i < n; i += 5) { k = 0; if (code[i] == '1') k += 16; if (code[i + 1] == '1' && i + 1 < n) k += 8; if (code[i + 2] == '1' && i + 2 < n) k += 4; if (code[i + 3] == '1' && i + 3 < n) k += 2; if (code[i + 4] == '1' && i + 4 < n) k += 1; printf("%c", decode[k]); } printf("\n"); } return 0; }
#include <stdio.h> #include <string.h> char encode[96][9]; char decode[32]; int main(void) { strcpy(encode[' '], "101"); strcpy(encode['\n'], ""); strcpy(encode['\''], "000000"); strcpy(encode[','], "000011"); strcpy(encode['-'], "10010001"); strcpy(encode['.'], "010001"); strcpy(encode['?'], "000001"); strcpy(encode['A'], "100101"); strcpy(encode['B'], "10011010"); strcpy(encode['C'], "0101"); strcpy(encode['D'], "0001"); strcpy(encode['E'], "110"); strcpy(encode['F'], "01001"); strcpy(encode['G'], "10011011"); strcpy(encode['H'], "010000"); strcpy(encode['I'], "0111"); strcpy(encode['J'], "10011000"); strcpy(encode['K'], "0110"); strcpy(encode['L'], "00100"); strcpy(encode['M'], "10011001"); strcpy(encode['N'], "10011110"); strcpy(encode['O'], "00101"); strcpy(encode['P'], "111"); strcpy(encode['Q'], "10011111"); strcpy(encode['R'], "1000"); strcpy(encode['S'], "00110"); strcpy(encode['T'], "00111"); strcpy(encode['U'], "10011100"); strcpy(encode['V'], "10011101"); strcpy(encode['W'], "000010"); strcpy(encode['X'], "10010010"); strcpy(encode['Y'], "10010011"); strcpy(encode['Z'], "10010000"); int n, i, k; char type[200], code[10000]; for (i = 0; i < 26; i++) { decode[i] = 'A' + i; } decode[26] = ' '; decode[27] = '.'; decode[28] = ','; decode[29] = '-'; decode[30] = '\''; decode[31] = '?'; while (fgets(type, 200, stdin) != NULL) { code[0] = '\0'; n = strlen(type); for (i = 0; i < n; i++) { strcat(code, encode[type[i]]); } n = strlen(code); for (i = 0; i < n; i += 5) { k = 0; if (code[i] == '1') k += 16; if (code[i + 1] == '1' && i + 1 < n) k += 8; if (code[i + 2] == '1' && i + 2 < n) k += 4; if (code[i + 3] == '1' && i + 3 < n) k += 2; if (code[i + 4] == '1' && i + 4 < n) k += 1; printf("%c", decode[k]); } printf("\n"); } return 0; }
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 15, 23, 0, 16, 31, 2, 3, 4, 0, 13], ["+", 15, 23, 0, 16, 31, 2, 3, 4, 0, 13]]
0
800
4
#include <iostream> #include <map> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; vector<string> split(string &str, char delim) { vector<string> res; size_t current = 0, found; while ((found = str.find_first_of(delim, current)) != string::npos) { res.push_back(string(str, current, found - current)); current = found + 1; } res.push_back(string(str, current, str.size() - current)); return res; } int main() { map<char, string> ID; ID[' '] = "101"; ID['\''] = "000000"; ID[','] = "000011"; ID['-'] = "100010001"; ID['.'] = "010001"; ID['?'] = "000001"; ID['A'] = "100101"; ID['B'] = "10011010"; ID['C'] = "0101"; ID['D'] = "0001"; ID['E'] = "110"; ID['F'] = "01001"; ID['G'] = "10011011"; ID['H'] = "010000"; ID['I'] = "0111"; ID['J'] = "10011000"; ID['K'] = "0110"; ID['L'] = "00100"; ID['M'] = "10011001"; ID['N'] = "100011110"; ID['O'] = "00101"; ID['P'] = "111"; ID['Q'] = "10011111"; ID['R'] = "1000"; ID['S'] = "00110"; ID['T'] = "00111"; ID['U'] = "10011100"; ID['V'] = "10011101"; ID['W'] = "000010"; ID['X'] = "10010010"; ID['Y'] = "10010011"; ID['Z'] = "10010000"; map<string, string> Id; Id["00000"] = "A"; Id["00001"] = "B"; Id["00010"] = "C"; Id["00011"] = "D"; Id["00100"] = "E"; Id["00101"] = "F"; Id["00110"] = "G"; Id["00111"] = "H"; Id["01000"] = "I"; Id["01001"] = "J"; Id["01010"] = "K"; Id["01011"] = "L"; Id["01100"] = "M"; Id["01101"] = "N"; Id["01110"] = "O"; Id["01111"] = "P"; Id["10000"] = "Q"; Id["10001"] = "R"; Id["10010"] = "S"; Id["10011"] = "T"; Id["10100"] = "U"; Id["10101"] = "V"; Id["10110"] = "W"; Id["10111"] = "X"; Id["11000"] = "Y"; Id["11001"] = "Z"; Id["11010"] = " "; Id["11011"] = "."; Id["11100"] = ","; Id["11101"] = "-"; Id["11110"] = "'"; Id["11111"] = "?"; string s; string str = ""; while (getline(cin, s)) { if (cin.eof()) break; rep(i, s.size()) { str += ID[s[i]]; } while (str.length() % 5 != 0) { str += "0"; } string ans = ""; while (str.length()) { string temp = str.substr(0, 5); ans += Id[temp]; str = str.substr(5); } cout << ans << endl; } return 0; }
#include <iostream> #include <map> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; vector<string> split(string &str, char delim) { vector<string> res; size_t current = 0, found; while ((found = str.find_first_of(delim, current)) != string::npos) { res.push_back(string(str, current, found - current)); current = found + 1; } res.push_back(string(str, current, str.size() - current)); return res; } int main() { map<char, string> ID; ID[' '] = "101"; ID['\''] = "000000"; ID[','] = "000011"; ID['-'] = "10010001"; ID['.'] = "010001"; ID['?'] = "000001"; ID['A'] = "100101"; ID['B'] = "10011010"; ID['C'] = "0101"; ID['D'] = "0001"; ID['E'] = "110"; ID['F'] = "01001"; ID['G'] = "10011011"; ID['H'] = "010000"; ID['I'] = "0111"; ID['J'] = "10011000"; ID['K'] = "0110"; ID['L'] = "00100"; ID['M'] = "10011001"; ID['N'] = "10011110"; ID['O'] = "00101"; ID['P'] = "111"; ID['Q'] = "10011111"; ID['R'] = "1000"; ID['S'] = "00110"; ID['T'] = "00111"; ID['U'] = "10011100"; ID['V'] = "10011101"; ID['W'] = "000010"; ID['X'] = "10010010"; ID['Y'] = "10010011"; ID['Z'] = "10010000"; map<string, string> Id; Id["00000"] = "A"; Id["00001"] = "B"; Id["00010"] = "C"; Id["00011"] = "D"; Id["00100"] = "E"; Id["00101"] = "F"; Id["00110"] = "G"; Id["00111"] = "H"; Id["01000"] = "I"; Id["01001"] = "J"; Id["01010"] = "K"; Id["01011"] = "L"; Id["01100"] = "M"; Id["01101"] = "N"; Id["01110"] = "O"; Id["01111"] = "P"; Id["10000"] = "Q"; Id["10001"] = "R"; Id["10010"] = "S"; Id["10011"] = "T"; Id["10100"] = "U"; Id["10101"] = "V"; Id["10110"] = "W"; Id["10111"] = "X"; Id["11000"] = "Y"; Id["11001"] = "Z"; Id["11010"] = " "; Id["11011"] = "."; Id["11100"] = ","; Id["11101"] = "-"; Id["11110"] = "'"; Id["11111"] = "?"; string s; string str = ""; while (getline(cin, s)) { if (cin.eof()) break; rep(i, s.size()) { str += ID[s[i]]; } while (str.length() % 5 != 0) { str += "0"; } string ans = ""; while (str.length()) { string temp = str.substr(0, 5); ans += Id[temp]; str = str.substr(5); } cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6]]
1
966
4
// The Code A Doctor Loved #include <bits/stdc++.h> using namespace std; string p(string s, string t) { for (int i = 0; i < t.length(); i++) { if (s.length() % 6 == 5) s += ' '; s += t[i]; } return s; } string into(string s) { string t = ""; for (int i = 0; i < s.length(); i++) { if (s[i] == ' ') t = p(t, "101"); if (s[i] == '\'') t = p(t, "000000"); if (s[i] == ',') t = p(t, "000011"); if (s[i] == '_') t = p(t, "10010001"); if (s[i] == '.') t = p(t, "010001"); if (s[i] == '?') t = p(t, "000001"); if (s[i] == 'A') t = p(t, "100101"); if (s[i] == 'B') t = p(t, "10011010"); if (s[i] == 'C') t = p(t, "0101"); if (s[i] == 'D') t = p(t, "0001"); if (s[i] == 'E') t = p(t, "110"); if (s[i] == 'F') t = p(t, "01001"); if (s[i] == 'G') t = p(t, "10011011"); if (s[i] == 'H') t = p(t, "010000"); if (s[i] == 'I') t = p(t, "0111"); if (s[i] == 'J') t = p(t, "10011000"); if (s[i] == 'K') t = p(t, "0110"); if (s[i] == 'L') t = p(t, "00100"); if (s[i] == 'M') t = p(t, "10011001"); if (s[i] == 'N') t = p(t, "10011110"); if (s[i] == 'O') t = p(t, "00101"); if (s[i] == 'P') t = p(t, "111"); if (s[i] == 'Q') t = p(t, "10011111"); if (s[i] == 'R') t = p(t, "1000"); if (s[i] == 'S') t = p(t, "00110"); if (s[i] == 'T') t = p(t, "00111"); if (s[i] == 'U') t = p(t, "10011100"); if (s[i] == 'V') t = p(t, "10011101"); if (s[i] == 'W') t = p(t, "000010"); if (s[i] == 'X') t = p(t, "10010010"); if (s[i] == 'Y') t = p(t, "10010011"); if (s[i] == 'Z') t = p(t, "10010000"); } while (t.length() % 6 != 5) t += '0'; stringstream ss(t); string ret = "", tmp; while (getline(ss, tmp, ' ')) { if (tmp == "00000") ret += 'A'; if (tmp == "00001") ret += 'B'; if (tmp == "00010") ret += 'C'; if (tmp == "00011") ret += 'D'; if (tmp == "00100") ret += 'E'; if (tmp == "00101") ret += 'F'; if (tmp == "00110") ret += 'G'; if (tmp == "00111") ret += 'H'; if (tmp == "01000") ret += 'I'; if (tmp == "01001") ret += 'J'; if (tmp == "01010") ret += 'K'; if (tmp == "01011") ret += 'L'; if (tmp == "01100") ret += 'M'; if (tmp == "01101") ret += 'N'; if (tmp == "01110") ret += 'O'; if (tmp == "01111") ret += 'P'; if (tmp == "10000") ret += 'Q'; if (tmp == "10001") ret += 'R'; if (tmp == "10010") ret += 'S'; if (tmp == "10011") ret += 'T'; if (tmp == "10100") ret += 'U'; if (tmp == "10101") ret += 'V'; if (tmp == "10110") ret += 'W'; if (tmp == "10111") ret += 'X'; if (tmp == "11000") ret += 'Y'; if (tmp == "11001") ret += 'Z'; if (tmp == "11010") ret += ' '; if (tmp == "11011") ret += '.'; if (tmp == "11100") ret += ','; if (tmp == "11101") ret += '_'; if (tmp == "11110") ret += '\''; if (tmp == "11111") ret += '?'; } return ret; } int main() { string s; while (getline(cin, s)) { cout << into(s) << endl; } return 0; }
// The Code A Doctor Loved #include <bits/stdc++.h> using namespace std; string p(string s, string t) { for (int i = 0; i < t.length(); i++) { if (s.length() % 6 == 5) s += ' '; s += t[i]; } return s; } string into(string s) { string t = ""; for (int i = 0; i < s.length(); i++) { if (s[i] == ' ') t = p(t, "101"); if (s[i] == '\'') t = p(t, "000000"); if (s[i] == ',') t = p(t, "000011"); if (s[i] == '-') t = p(t, "10010001"); if (s[i] == '.') t = p(t, "010001"); if (s[i] == '?') t = p(t, "000001"); if (s[i] == 'A') t = p(t, "100101"); if (s[i] == 'B') t = p(t, "10011010"); if (s[i] == 'C') t = p(t, "0101"); if (s[i] == 'D') t = p(t, "0001"); if (s[i] == 'E') t = p(t, "110"); if (s[i] == 'F') t = p(t, "01001"); if (s[i] == 'G') t = p(t, "10011011"); if (s[i] == 'H') t = p(t, "010000"); if (s[i] == 'I') t = p(t, "0111"); if (s[i] == 'J') t = p(t, "10011000"); if (s[i] == 'K') t = p(t, "0110"); if (s[i] == 'L') t = p(t, "00100"); if (s[i] == 'M') t = p(t, "10011001"); if (s[i] == 'N') t = p(t, "10011110"); if (s[i] == 'O') t = p(t, "00101"); if (s[i] == 'P') t = p(t, "111"); if (s[i] == 'Q') t = p(t, "10011111"); if (s[i] == 'R') t = p(t, "1000"); if (s[i] == 'S') t = p(t, "00110"); if (s[i] == 'T') t = p(t, "00111"); if (s[i] == 'U') t = p(t, "10011100"); if (s[i] == 'V') t = p(t, "10011101"); if (s[i] == 'W') t = p(t, "000010"); if (s[i] == 'X') t = p(t, "10010010"); if (s[i] == 'Y') t = p(t, "10010011"); if (s[i] == 'Z') t = p(t, "10010000"); } while (t.length() % 6 != 5) t += '0'; stringstream ss(t); string ret = "", tmp; while (getline(ss, tmp, ' ')) { if (tmp == "00000") ret += 'A'; if (tmp == "00001") ret += 'B'; if (tmp == "00010") ret += 'C'; if (tmp == "00011") ret += 'D'; if (tmp == "00100") ret += 'E'; if (tmp == "00101") ret += 'F'; if (tmp == "00110") ret += 'G'; if (tmp == "00111") ret += 'H'; if (tmp == "01000") ret += 'I'; if (tmp == "01001") ret += 'J'; if (tmp == "01010") ret += 'K'; if (tmp == "01011") ret += 'L'; if (tmp == "01100") ret += 'M'; if (tmp == "01101") ret += 'N'; if (tmp == "01110") ret += 'O'; if (tmp == "01111") ret += 'P'; if (tmp == "10000") ret += 'Q'; if (tmp == "10001") ret += 'R'; if (tmp == "10010") ret += 'S'; if (tmp == "10011") ret += 'T'; if (tmp == "10100") ret += 'U'; if (tmp == "10101") ret += 'V'; if (tmp == "10110") ret += 'W'; if (tmp == "10111") ret += 'X'; if (tmp == "11000") ret += 'Y'; if (tmp == "11001") ret += 'Z'; if (tmp == "11010") ret += ' '; if (tmp == "11011") ret += '.'; if (tmp == "11100") ret += ','; if (tmp == "11101") ret += '-'; if (tmp == "11110") ret += '\''; if (tmp == "11111") ret += '?'; } return ret; } int main() { string s; while (getline(cin, s)) { cout << into(s) << endl; } return 0; }
[["-", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125], ["+", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125], ["-", 0, 57, 64, 1, 0, 11, 12, 103, 0, 125], ["+", 0, 57, 64, 1, 0, 11, 12, 103, 0, 125]]
1
1,334
4
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <string> #include <time.h> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define pb push_back #define mp make_pair #define all(in) in.begin(), in.end() const double PI = acos(-1); const double EPS = 1e-10; const int inf = 1e8; using namespace std; typedef long long ll; typedef vector<int> vi; int n; int main() { map<char, string> in; in[' '] = "101"; in['\''] = "000000"; in[','] = "000011"; in['-'] = "10010001"; in['.'] = "010001"; in['?'] = "000001"; in['A'] = "100101"; in['B'] = "10011010"; in['C'] = "0101"; in['D'] = "0001"; in['E'] = "110"; in['F'] = "01001"; in['G'] = "10011011"; in['H'] = "010000"; in['I'] = "0111"; in['J'] = "10011000"; in['K'] = "0110"; in['L'] = "00100"; in['M'] = "10011001"; in['N'] = "10011110"; in['O'] = "00101"; in['P'] = "111"; in['Q'] = "10011111"; in['R'] = "1000"; in['S'] = "00110"; in['T'] = "00111"; in['U'] = "10011100"; in['V'] = "10011101"; in['W'] = "00010"; in['X'] = "10010010"; in['Y'] = "10010011"; in['Z'] = "10010000"; map<string, char> out; out["00000"] = 'A'; out["00001"] = 'B'; out["00010"] = 'C'; out["00011"] = 'D'; out["00100"] = 'E'; out["00101"] = 'F'; out["00110"] = 'G'; out["00111"] = 'H'; out["01000"] = 'I'; out["01001"] = 'J'; out["01010"] = 'K'; out["01011"] = 'L'; out["01100"] = 'M'; out["01101"] = 'N'; out["01110"] = 'O'; out["01111"] = 'P'; out["10000"] = 'Q'; out["10001"] = 'R'; out["10010"] = 'S'; out["10011"] = 'T'; out["10100"] = 'U'; out["10101"] = 'V'; out["10110"] = 'W'; out["10111"] = 'X'; out["11000"] = 'Y'; out["11001"] = 'Z'; out["11010"] = ' '; out["11011"] = '.'; out["11100"] = ','; out["11101"] = '-'; out["11110"] = '\''; out["11111"] = '?'; string s; while (getline(cin, s)) { string a = ""; rep(i, s.size()) a += in[s[i]]; while (a.size() % 5) a += '0'; rep(i, a.size() / 5) cout << out[a.substr(i * 5, 5)] << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <string> #include <time.h> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define pb push_back #define mp make_pair #define all(in) in.begin(), in.end() const double PI = acos(-1); const double EPS = 1e-10; const int inf = 1e8; using namespace std; typedef long long ll; typedef vector<int> vi; int n; int main() { map<char, string> in; in[' '] = "101"; in['\''] = "000000"; in[','] = "000011"; in['-'] = "10010001"; in['.'] = "010001"; in['?'] = "000001"; in['A'] = "100101"; in['B'] = "10011010"; in['C'] = "0101"; in['D'] = "0001"; in['E'] = "110"; in['F'] = "01001"; in['G'] = "10011011"; in['H'] = "010000"; in['I'] = "0111"; in['J'] = "10011000"; in['K'] = "0110"; in['L'] = "00100"; in['M'] = "10011001"; in['N'] = "10011110"; in['O'] = "00101"; in['P'] = "111"; in['Q'] = "10011111"; in['R'] = "1000"; in['S'] = "00110"; in['T'] = "00111"; in['U'] = "10011100"; in['V'] = "10011101"; in['W'] = "000010"; in['X'] = "10010010"; in['Y'] = "10010011"; in['Z'] = "10010000"; map<string, char> out; out["00000"] = 'A'; out["00001"] = 'B'; out["00010"] = 'C'; out["00011"] = 'D'; out["00100"] = 'E'; out["00101"] = 'F'; out["00110"] = 'G'; out["00111"] = 'H'; out["01000"] = 'I'; out["01001"] = 'J'; out["01010"] = 'K'; out["01011"] = 'L'; out["01100"] = 'M'; out["01101"] = 'N'; out["01110"] = 'O'; out["01111"] = 'P'; out["10000"] = 'Q'; out["10001"] = 'R'; out["10010"] = 'S'; out["10011"] = 'T'; out["10100"] = 'U'; out["10101"] = 'V'; out["10110"] = 'W'; out["10111"] = 'X'; out["11000"] = 'Y'; out["11001"] = 'Z'; out["11010"] = ' '; out["11011"] = '.'; out["11100"] = ','; out["11101"] = '-'; out["11110"] = '\''; out["11111"] = '?'; string s; while (getline(cin, s)) { string a = ""; rep(i, s.size()) a += in[s[i]]; while (a.size() % 5) a += '0'; rep(i, a.size() / 5) cout << out[a.substr(i * 5, 5)]; cout << endl; } }
[["-", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22]]
1
904
4
#include <bits/stdc++.h> using namespace std; int main() { map<char, string> P; P[32] = "101"; P[39] = "000000"; P[44] = "000011"; P[45] = "10010001"; P[46] = "010001"; P[63] = "000001"; P[65] = "100101"; // A P[66] = "10011010"; P[67] = "0101"; P[68] = "0001"; P[69] = "110"; P[70] = "01001"; P[71] = "10011011"; P[72] = "010000"; P[73] = "0111"; P[74] = "10011000"; P[75] = "0110"; P[76] = "00100"; P[77] = "10011001"; P[78] = "10011110"; P[79] = "00101"; P[80] = "111"; P[81] = "10011111"; P[82] = "1000"; P[83] = "00110"; P[84] = "00111"; P[85] = "10011100"; P[86] = "10011101"; P[87] = "000010"; P[88] = "10010010"; P[89] = "10010011"; P[90] = "10010000"; map<string, string> PP; PP["00000"] = 'A'; PP["00001"] = 'B'; PP["00010"] = 'C'; PP["00011"] = 'D'; PP["00100"] = 'E'; PP["00101"] = 'F'; PP["00110"] = 'G'; PP["00111"] = 'H'; PP["01000"] = 'I'; PP["01001"] = 'J'; PP["01010"] = 'K'; PP["01011"] = 'L'; PP["01100"] = 'M'; PP["01101"] = 'N'; PP["01110"] = 'O'; PP["01111"] = 'P'; PP["10000"] = 'Q'; PP["10001"] = 'R'; PP["10010"] = 'S'; PP["10011"] = 'T'; PP["10100"] = 'U'; PP["10101"] = 'V'; PP["10110"] = 'W'; PP["10111"] = 'X'; PP["11000"] = 'Y'; PP["11001"] = 'Z'; PP["11010"] = ' '; PP["11011"] = '.'; PP["11100"] = ','; PP["11101"] = '-'; PP["11110"] = ','; PP["11111"] = '?'; string str; while (getline(cin, str)) { int count = 0; string set_str; string keep; string ans_str; for (int i = 0; i < str.length(); i++) { set_str += P[str[i]]; } while (set_str.length() % 5) set_str += '0'; for (int i = 0; i < set_str.length(); i++) { ans_str += set_str[i]; count++; if (!(count % 5) && count) { cout << PP[ans_str]; ans_str.erase(ans_str.begin(), ans_str.end()); } } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { map<char, string> P; P[32] = "101"; P[39] = "000000"; P[44] = "000011"; P[45] = "10010001"; P[46] = "010001"; P[63] = "000001"; P[65] = "100101"; // A P[66] = "10011010"; P[67] = "0101"; P[68] = "0001"; P[69] = "110"; P[70] = "01001"; P[71] = "10011011"; P[72] = "010000"; P[73] = "0111"; P[74] = "10011000"; P[75] = "0110"; P[76] = "00100"; P[77] = "10011001"; P[78] = "10011110"; P[79] = "00101"; P[80] = "111"; P[81] = "10011111"; P[82] = "1000"; P[83] = "00110"; P[84] = "00111"; P[85] = "10011100"; P[86] = "10011101"; P[87] = "000010"; P[88] = "10010010"; P[89] = "10010011"; P[90] = "10010000"; map<string, string> PP; PP["00000"] = 'A'; PP["00001"] = 'B'; PP["00010"] = 'C'; PP["00011"] = 'D'; PP["00100"] = 'E'; PP["00101"] = 'F'; PP["00110"] = 'G'; PP["00111"] = 'H'; PP["01000"] = 'I'; PP["01001"] = 'J'; PP["01010"] = 'K'; PP["01011"] = 'L'; PP["01100"] = 'M'; PP["01101"] = 'N'; PP["01110"] = 'O'; PP["01111"] = 'P'; PP["10000"] = 'Q'; PP["10001"] = 'R'; PP["10010"] = 'S'; PP["10011"] = 'T'; PP["10100"] = 'U'; PP["10101"] = 'V'; PP["10110"] = 'W'; PP["10111"] = 'X'; PP["11000"] = 'Y'; PP["11001"] = 'Z'; PP["11010"] = ' '; PP["11011"] = '.'; PP["11100"] = ','; PP["11101"] = '-'; PP["11110"] = "'"; PP["11111"] = '?'; string str; while (getline(cin, str)) { int count = 0; string set_str; string keep; string ans_str; for (int i = 0; i < str.length(); i++) { set_str += P[str[i]]; } while (set_str.length() % 5) set_str += '0'; for (int i = 0; i < set_str.length(); i++) { ans_str += set_str[i]; count++; if (!(count % 5) && count) { cout << PP[ans_str]; ans_str.erase(ans_str.begin(), ans_str.end()); } } cout << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 103, 0, 104], ["-", 8, 9, 0, 1, 0, 11, 12, 103, 0, 125], ["+", 8, 9, 0, 1, 0, 11, 12, 5, 0, 62]]
1
817
4
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<long long, int> ll_i; typedef pair<double, int> d_i; typedef pair<long long, long long> ll_ll; typedef pair<double, double> d_d; #define PI 3.141592653589793238462643383279 #define mod 1000000007LL #define rep(i, n) for (i = 0; i < n; ++i) #define rep1(i, n) for (i = 1; i < n; ++i) #define rep2d(i, j, n) \ for (i = 0; i < n; ++i) \ for (j = i + 1; j < n; ++j) #define per(i, n) for (i = n - 1; i > -1; --i) #define int(x) \ int x; \ scanf("%d", &x) #define int2(x, y) \ int x, y; \ scanf("%d%d", &x, &y) #define int3(x, y, z) \ int x, y, z; \ scanf("%d%d%d", &x, &y, &z) #define sc(x) cin >> x #define sc2(x, y) cin >> x >> y #define sc3(x, y, z) cin >> x >> y >> z #define scn(n, a) rep(i, n) cin >> a[i] #define sc2n(n, a, b) rep(i, n) cin >> a[i] >> b[i] #define pri(x) cout << x << "\n" #define pri2(x, y) cout << x << " " << y << "\n" #define pri3(x, y, z) cout << x << " " << y << " " << z << "\n" #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define endl "\n" #define kabe puts("---------------------------") #define kara puts("") #define debug(x) cout << " --- " << x << "\n" #define debug2(x, y) cout << " --- " << x << " " << y << "\n" #define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n" #define X first #define Y second #define eps 0.0001 #define prid(x) printf("%.15lf\n", x) string be = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string lis[32]; string af = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ',-.?"; int f(string x) { int a = (int)(x[0] - '0') * 16; int b = (int)(x[1] - '0') * 8; int c = (int)(x[2] - '0') * 4; int d = (int)(x[3] - '0') * 2; int e = (int)(x[4] - '0') * 1; return a + b + c + d + e; } signed main(void) { int i, j, k; lis[0] = "101"; lis[1] = "000000"; lis[2] = "000011"; lis[3] = "10010001"; lis[4] = "010001"; lis[5] = "000001"; lis[6] = "100101"; lis[7] = "10011010"; lis[8] = "0101"; lis[9] = "0001"; lis[10] = "110"; lis[11] = "01001"; lis[12] = "10011011"; lis[13] = "010000"; lis[14] = "0111"; lis[15] = "10011000"; lis[16] = "0110"; lis[17] = "00100"; lis[18] = "10011001"; lis[19] = "10011110"; lis[20] = "00101"; lis[21] = "111"; lis[22] = "10011111"; lis[23] = "1000"; lis[24] = "00110"; lis[25] = "00111"; lis[26] = "10011100"; lis[27] = "10011101"; lis[28] = "000010"; lis[29] = "10010010"; lis[30] = "10010011"; lis[31] = "10010000"; string s; for (int testcase = 0; getline(cin, s); testcase++) { string rmn = ""; rep(i, s.size()) { rep(j, be.size()) if (s[i] == be[j]) break; rmn += lis[j]; } int tmp = (5 - (rmn.size() % 5)) % 5; rep(i, tmp) rmn += "0"; string res = ""; for (i = 0; i < rmn.size(); i += 5) res += af[f(rmn.substr(i, 5))]; pri(res); s.clear(); } return 0; }
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<long long, int> ll_i; typedef pair<double, int> d_i; typedef pair<long long, long long> ll_ll; typedef pair<double, double> d_d; #define PI 3.141592653589793238462643383279 #define mod 1000000007LL #define rep(i, n) for (i = 0; i < n; ++i) #define rep1(i, n) for (i = 1; i < n; ++i) #define rep2d(i, j, n) \ for (i = 0; i < n; ++i) \ for (j = i + 1; j < n; ++j) #define per(i, n) for (i = n - 1; i > -1; --i) #define int(x) \ int x; \ scanf("%d", &x) #define int2(x, y) \ int x, y; \ scanf("%d%d", &x, &y) #define int3(x, y, z) \ int x, y, z; \ scanf("%d%d%d", &x, &y, &z) #define sc(x) cin >> x #define sc2(x, y) cin >> x >> y #define sc3(x, y, z) cin >> x >> y >> z #define scn(n, a) rep(i, n) cin >> a[i] #define sc2n(n, a, b) rep(i, n) cin >> a[i] >> b[i] #define pri(x) cout << x << "\n" #define pri2(x, y) cout << x << " " << y << "\n" #define pri3(x, y, z) cout << x << " " << y << " " << z << "\n" #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define endl "\n" #define kabe puts("---------------------------") #define kara puts("") #define debug(x) cout << " --- " << x << "\n" #define debug2(x, y) cout << " --- " << x << " " << y << "\n" #define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n" #define X first #define Y second #define eps 0.0001 #define prid(x) printf("%.15lf\n", x) string be = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string lis[32]; string af = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"; int f(string x) { int a = (int)(x[0] - '0') * 16; int b = (int)(x[1] - '0') * 8; int c = (int)(x[2] - '0') * 4; int d = (int)(x[3] - '0') * 2; int e = (int)(x[4] - '0') * 1; return a + b + c + d + e; } signed main(void) { int i, j, k; lis[0] = "101"; lis[1] = "000000"; lis[2] = "000011"; lis[3] = "10010001"; lis[4] = "010001"; lis[5] = "000001"; lis[6] = "100101"; lis[7] = "10011010"; lis[8] = "0101"; lis[9] = "0001"; lis[10] = "110"; lis[11] = "01001"; lis[12] = "10011011"; lis[13] = "010000"; lis[14] = "0111"; lis[15] = "10011000"; lis[16] = "0110"; lis[17] = "00100"; lis[18] = "10011001"; lis[19] = "10011110"; lis[20] = "00101"; lis[21] = "111"; lis[22] = "10011111"; lis[23] = "1000"; lis[24] = "00110"; lis[25] = "00111"; lis[26] = "10011100"; lis[27] = "10011101"; lis[28] = "000010"; lis[29] = "10010010"; lis[30] = "10010011"; lis[31] = "10010000"; string s; for (int testcase = 0; getline(cin, s); testcase++) { string rmn = ""; rep(i, s.size()) { rep(j, be.size()) if (s[i] == be[j]) break; rmn += lis[j]; } int tmp = (5 - (rmn.size() % 5)) % 5; rep(i, tmp) rmn += "0"; string res = ""; for (i = 0; i < rmn.size(); i += 5) res += af[f(rmn.substr(i, 5))]; pri(res); s.clear(); } return 0; }
[["-", 0, 30, 0, 43, 49, 50, 51, 5, 0, 6], ["+", 0, 30, 0, 43, 49, 50, 51, 5, 0, 6]]
1
896
2
#include <algorithm> #include <cmath> #include <queue> #include <stack> #include <stdio.h> using namespace std; using namespace std; int main() { char base[205], middle[900], result[900]; int p, tmp; while (fgets(base, 205, stdin) != 0) { p = 0; for (int i = 0; base[i] != '\0'; i++) { switch (base[i]) { case ' ': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; break; case '\'': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; break; case ',': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; break; case '_': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case '.': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case '?': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case 'A': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; break; case 'B': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; break; case 'C': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; break; case 'D': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case 'E': middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; break; case 'F': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case 'G': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; break; case 'H': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; break; case 'I': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; break; case 'J': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; break; case 'K': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; break; case 'L': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; break; case 'M': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case 'N': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; break; case 'O': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; break; case 'P': middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; break; case 'Q': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; break; case 'R': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; break; case 'S': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; break; case 'T': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; break; case 'U': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; break; case 'V': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; break; case 'W': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; break; case 'X': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; break; case 'Y': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; break; case 'Z': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; break; } } if (p % 5 == 1) { middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; } else if (p % 5 == 2) { middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; } else if (p % 5 == 3) { middle[p++] = '0'; middle[p++] = '0'; } else if (p % 5 == 4) { middle[p++] = '0'; } middle[p] = '\0'; p = 0; for (int i = 0; middle[i] != '\0'; i += 5) { tmp = 16 * (middle[i] - '0') + 8 * (middle[i + 1] - '0') + 4 * (middle[i + 2] - '0') + 2 * (middle[i + 3] - '0') + (middle[i + 4] - '0'); if (tmp <= 25) { result[p++] = 'A' + tmp; } else { switch (tmp) { case 26: result[p++] = ' '; break; case 27: result[p++] = '.'; break; case 28: result[p++] = ','; break; case 29: result[p++] = '_'; break; case 30: result[p++] = '\''; break; case 31: result[p++] = '?'; break; } } if (middle[i + 5] == '\0') { result[p] = '\0'; break; } } printf("%s\n", result); } return 0; }
#include <algorithm> #include <cmath> #include <queue> #include <stack> #include <stdio.h> using namespace std; using namespace std; int main() { char base[205], middle[900], result[900]; int p, tmp; while (fgets(base, 205, stdin) != 0) { p = 0; for (int i = 0; base[i] != '\0'; i++) { switch (base[i]) { case ' ': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; break; case '\'': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; break; case ',': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; break; case '-': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case '.': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case '?': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case 'A': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; break; case 'B': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; break; case 'C': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; break; case 'D': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case 'E': middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; break; case 'F': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case 'G': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; break; case 'H': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; break; case 'I': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; break; case 'J': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; break; case 'K': middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; break; case 'L': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; break; case 'M': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; break; case 'N': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; break; case 'O': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; break; case 'P': middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; break; case 'Q': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; break; case 'R': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; break; case 'S': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; break; case 'T': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; break; case 'U': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; break; case 'V': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '1'; break; case 'W': middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; break; case 'X': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; break; case 'Y': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '1'; break; case 'Z': middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '1'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; break; } } if (p % 5 == 1) { middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; } else if (p % 5 == 2) { middle[p++] = '0'; middle[p++] = '0'; middle[p++] = '0'; } else if (p % 5 == 3) { middle[p++] = '0'; middle[p++] = '0'; } else if (p % 5 == 4) { middle[p++] = '0'; } middle[p] = '\0'; p = 0; for (int i = 0; middle[i] != '\0'; i += 5) { tmp = 16 * (middle[i] - '0') + 8 * (middle[i + 1] - '0') + 4 * (middle[i + 2] - '0') + 2 * (middle[i + 3] - '0') + (middle[i + 4] - '0'); if (tmp <= 25) { result[p++] = 'A' + tmp; } else { switch (tmp) { case 26: result[p++] = ' '; break; case 27: result[p++] = '.'; break; case 28: result[p++] = ','; break; case 29: result[p++] = '-'; break; case 30: result[p++] = '\''; break; case 31: result[p++] = '?'; break; } } if (middle[i + 5] == '\0') { result[p] = '\0'; break; } } printf("%s\n", result); } return 0; }
[["-", 0, 99, 8, 9, 0, 100, 51, 103, 0, 125], ["+", 0, 99, 8, 9, 0, 100, 51, 103, 0, 125], ["-", 0, 100, 0, 1, 0, 11, 12, 103, 0, 125], ["+", 0, 100, 0, 1, 0, 11, 12, 103, 0, 125]]
1
2,647
4
#include <algorithm> #include <cmath> #include <iostream> #include <string> using namespace std; string DoctorTableAD(char c) { string s; switch (c) { case ' ': s = "101"; break; case 0x27: s = "000000"; break; case ',': s = "000011"; break; case '-': s = "10010001"; break; case '.': s = "010001"; break; case '?': s = "000001"; break; case 'A': s = "100101"; break; case 'B': s = "10011010"; break; case 'C': s = "0101"; break; case 'D': s = "0001"; break; case 'E': s = "110"; break; case 'F': s = "01001"; break; case 'G': s = "10011011"; break; case 'H': s = "010000"; break; case 'I': s = "0111"; break; case 'J': s = "10011000"; break; case 'K': s = "0110"; break; case 'L': s = "00100"; break; case 'M': s = "10011001"; break; case 'N': s = "10011110"; break; case 'O': s = "00101"; break; case 'P': s = "111"; break; case 'Q': s = "10011111"; break; case 'R': s = "1000"; break; case 'S': s = "00110"; break; case 'T': s = "00111"; break; case 'U': s = "10011100"; break; case 'V': s = "10011101"; break; case 'W': s = "000010"; break; case 'X': s = "10010010"; break; case 'Y': s = "10010011"; break; case 'Z': s = "10010000"; break; } return s; } int myatoi(string bin_s) { int ret = 0; while (bin_s.length() > 0) { ret += (int)((bin_s[0] - '0') * pow(2.0, (double)(bin_s.length() - 1))); bin_s.erase(0, 1); } return ret; } char DoctorTableDA(string &s) { int d = myatoi(s); char ac[] = " .,-'?"; for (int i = 0; i < 'Z' - 'A'; i++) if (d == i) return i + 'A'; for (int i = 0; i < sizeof(ac) / sizeof(*ac); i++) if (i + 26 == d) return ac[i]; return ' '; } string DoctorLovedEncode(string &raw) { string s; string ret; for (unsigned int i = 0; i < raw.length(); i++) { s += DoctorTableAD(raw[i]); } // padding while (s.length() % 5 != 0) s += '0'; for (unsigned int i = 0; i < s.length() / 5; i++) { string subs = s.substr(i * 5, 5); ret += DoctorTableDA(subs); } return ret; } int main(void) { while (true) { string s; while (true) { char c; c = cin.get(); if (cin.eof()) return 0; if (c == '\n') break; else s += c; } cout << DoctorLovedEncode(s) << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> using namespace std; string DoctorTableAD(char c) { string s; switch (c) { case ' ': s = "101"; break; case 0x27: s = "000000"; break; case ',': s = "000011"; break; case '-': s = "10010001"; break; case '.': s = "010001"; break; case '?': s = "000001"; break; case 'A': s = "100101"; break; case 'B': s = "10011010"; break; case 'C': s = "0101"; break; case 'D': s = "0001"; break; case 'E': s = "110"; break; case 'F': s = "01001"; break; case 'G': s = "10011011"; break; case 'H': s = "010000"; break; case 'I': s = "0111"; break; case 'J': s = "10011000"; break; case 'K': s = "0110"; break; case 'L': s = "00100"; break; case 'M': s = "10011001"; break; case 'N': s = "10011110"; break; case 'O': s = "00101"; break; case 'P': s = "111"; break; case 'Q': s = "10011111"; break; case 'R': s = "1000"; break; case 'S': s = "00110"; break; case 'T': s = "00111"; break; case 'U': s = "10011100"; break; case 'V': s = "10011101"; break; case 'W': s = "000010"; break; case 'X': s = "10010010"; break; case 'Y': s = "10010011"; break; case 'Z': s = "10010000"; break; } return s; } int myatoi(string bin_s) { int ret = 0; while (bin_s.length() > 0) { ret += (int)((bin_s[0] - '0') * pow(2.0, (double)(bin_s.length() - 1))); bin_s.erase(0, 1); } return ret; } char DoctorTableDA(string &s) { int d = myatoi(s); char ac[] = " .,-'?"; for (int i = 0; i < 'Z' - 'A' + 1; i++) if (d == i) return i + 'A'; for (int i = 0; i < sizeof(ac) / sizeof(*ac); i++) if (i + 26 == d) return ac[i]; return ' '; } string DoctorLovedEncode(string &raw) { string s; string ret; for (unsigned int i = 0; i < raw.length(); i++) { s += DoctorTableAD(raw[i]); } // padding while (s.length() % 5 != 0) s += '0'; for (unsigned int i = 0; i < s.length() / 5; i++) { string subs = s.substr(i * 5, 5); ret += DoctorTableDA(subs); } return ret; } int main(void) { while (true) { string s; while (true) { char c; c = cin.get(); if (cin.eof()) return 0; if (c == '\n') break; else s += c; } cout << DoctorLovedEncode(s) << endl; } return 0; }
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
803
28
#include <algorithm> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() string itob(int a) { string ret; for (int i = 16; i > 0; i /= 2) { if (a >= i) { ret += '1'; a -= i; } else ret += '0'; } return ret; } int main() { string hoge = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"; map<string, string> m; REP(i, hoge.length()) { string hage; hage = hoge[i]; m.insert(make_pair(itob(i), hage)); } hoge = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string hoge2[] = {"101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"}; map<char, string> m2; REP(i, hoge.length()) m2.insert(make_pair(hoge[i], hoge2[i])); string line; while (!cin.eof()) { getline(cin, line); if (cin.eof()) break; string a; REP(i, line.length()) { a += m2[line[i]]; } int aa = a.length() % 5; if (aa) a += string(aa, '0'); string ans; for (int i = 0; i < a.length(); i += 5) { ans += m[a.substr(i, 5)]; } // cout << a << endl; cout << ans << endl; } }
#include <algorithm> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() string itob(int a) { string ret; for (int i = 16; i > 0; i /= 2) { if (a >= i) { ret += '1'; a -= i; } else ret += '0'; } return ret; } int main() { string hoge = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"; map<string, string> m; REP(i, hoge.length()) { string hage; hage = hoge[i]; m.insert(make_pair(itob(i), hage)); } hoge = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string hoge2[] = {"101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"}; map<char, string> m2; REP(i, hoge.length()) m2.insert(make_pair(hoge[i], hoge2[i])); string line; while (!cin.eof()) { getline(cin, line); if (cin.eof()) break; string a; REP(i, line.length()) a += m2[line[i]]; int aa = a.length() % 5; if (aa) a += string(5 - aa, '0'); string ans; for (int i = 0; i < a.length(); i += 5) { ans += m[a.substr(i, 5)]; } // cout << a << endl; cout << ans << endl; } }
[["-", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35], ["-", 8, 9, 0, 52, 8, 9, 0, 9, 0, 45], ["-", 8, 9, 0, 52, 8, 9, 0, 9, 0, 46], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 31, 13], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 33]]
1
460
5
#include <algorithm> #include <iostream> #include <map> #include <string> using namespace std; string i_to_05b(unsigned int n) { string s = ""; do { char c = (n & 1U) + '0'; s.push_back(c); n >>= 1; } while (n != 0); while (s.size() < 5) s.push_back('0'); reverse(s.begin(), s.end()); return s; } void makeTable1(map<char, string> &table1) { table1[' '] = "101"; table1['\''] = "000000"; table1[','] = "000011"; table1['-'] = "10010001"; table1['.'] = "010001"; table1['?'] = "000001"; table1['A'] = "100101"; table1['B'] = "10011010"; table1['C'] = "0101"; table1['D'] = "0001"; table1['E'] = "110"; table1['F'] = "01001"; table1['G'] = "10011011"; table1['H'] = "010000"; table1['I'] = "0111"; table1['J'] = "10011000"; table1['K'] = "0110"; table1['L'] = "00100"; table1['M'] = "10011001"; table1['N'] = "10011110"; table1['O'] = "00101"; table1['P'] = "111"; table1['Q'] = "10011111"; table1['R'] = "1000"; table1['S'] = "00110"; table1['T'] = "00111"; table1['U'] = "10011100"; table1['V'] = "10011101"; table1['W'] = "000010"; table1['X'] = "10010010"; table1['Y'] = "10010011"; table1['Z'] = "10010000"; } void makeTable2(map<string, char> &table2) { for (char c = 'A'; c <= 'Z'; ++c) { table2[i_to_05b((int)(c - 'A'))] = c; } table2["11010"] = ' '; table2["11011"] = '.'; table2["11100"] = ','; table2["11101"] = '-'; table2["11110"] = '\''; table2["11111"] = '?'; } string encode(string p, map<char, string> table1) { string c = ""; for (int i = 0; i < p.size(); ++i) { c += table1[p[i]]; } return c; } string decode(string c, map<string, char> table2) { string p = ""; while (c.size() % 5 != 0) { c.push_back('0'); } for (int i = 0; i + 5 <= c.size(); i += 5) { p.push_back(table2[c.substr(i, 5)]); } return p; } int main() { string p; map<char, string> table1; map<string, char> table2; makeTable1(table1); makeTable2(table2); while (cin >> p) { // cout << decode( "000000000100" , table2 ) << endl; cout << decode(encode(p, table1), table2) << endl; // cout << decode( encode( "PETER POTTER" , table1 ) , table2) << endl; } }
#include <algorithm> #include <iostream> #include <map> #include <string> using namespace std; string i_to_05b(unsigned int n) { string s = ""; do { char c = (n & 1U) + '0'; s.push_back(c); n >>= 1; } while (n != 0); while (s.size() < 5) s.push_back('0'); reverse(s.begin(), s.end()); return s; } void makeTable1(map<char, string> &table1) { table1[' '] = "101"; table1['\''] = "000000"; table1[','] = "000011"; table1['-'] = "10010001"; table1['.'] = "010001"; table1['?'] = "000001"; table1['A'] = "100101"; table1['B'] = "10011010"; table1['C'] = "0101"; table1['D'] = "0001"; table1['E'] = "110"; table1['F'] = "01001"; table1['G'] = "10011011"; table1['H'] = "010000"; table1['I'] = "0111"; table1['J'] = "10011000"; table1['K'] = "0110"; table1['L'] = "00100"; table1['M'] = "10011001"; table1['N'] = "10011110"; table1['O'] = "00101"; table1['P'] = "111"; table1['Q'] = "10011111"; table1['R'] = "1000"; table1['S'] = "00110"; table1['T'] = "00111"; table1['U'] = "10011100"; table1['V'] = "10011101"; table1['W'] = "000010"; table1['X'] = "10010010"; table1['Y'] = "10010011"; table1['Z'] = "10010000"; } void makeTable2(map<string, char> &table2) { for (char c = 'A'; c <= 'Z'; ++c) { table2[i_to_05b((int)(c - 'A'))] = c; } table2["11010"] = ' '; table2["11011"] = '.'; table2["11100"] = ','; table2["11101"] = '-'; table2["11110"] = '\''; table2["11111"] = '?'; } string encode(string p, map<char, string> table1) { string c = ""; for (int i = 0; i < p.size(); ++i) { c += table1[p[i]]; } return c; } string decode(string c, map<string, char> table2) { string p = ""; while (c.size() % 5 != 0) { c.push_back('0'); } for (int i = 0; i + 5 <= c.size(); i += 5) { p.push_back(table2[c.substr(i, 5)]); } return p; } int main() { string p; map<char, string> table1; map<string, char> table2; makeTable1(table1); makeTable2(table2); while (getline(cin, p)) { // cout << decode( "000000000100" , table2 ) << endl; cout << decode(encode(p, table1), table2) << endl; // cout << decode( encode( "PETER POTTER" , table1 ) , table2) << endl; } }
[["+", 8, 9, 0, 52, 15, 339, 51, 2, 63, 22], ["+", 0, 52, 15, 339, 51, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 152], ["+", 0, 52, 15, 339, 51, 2, 3, 4, 0, 21], ["+", 0, 52, 15, 339, 51, 2, 3, 4, 0, 25]]
1
787
5
#include <iostream> #include <map> #include <string> using namespace std; int main() { string str; map<string, string> encode; map<string, string> decode; encode[" "] = "101"; encode["'"] = "000000"; encode[","] = "000011"; encode["-"] = "10010001"; encode["."] = "010001"; encode["?"] = "000001"; encode["A"] = "100101"; encode["B"] = "10011010"; encode["C"] = "0101"; encode["D"] = "0001"; encode["E"] = "110"; encode["F"] = "01001"; encode["G"] = "10011011"; encode["H"] = "010000"; encode["I"] = "0111"; encode["J"] = "10011000"; encode["K"] = "0110"; encode["L"] = "00100"; encode["M"] = "10011001"; encode["N"] = "10011110"; encode["O"] = "00101"; encode["P"] = "111"; encode["Q"] = "10011111"; encode["R"] = "1000"; encode["S"] = "00110"; encode["T"] = "00111"; encode["U"] = "10011100"; encode["V"] = "10011101"; encode["W"] = "000010"; encode["X"] = "10010010"; encode["Y"] = "10010011"; encode["Z"] = "10010000"; decode["00000"] = "A"; decode["00001"] = "B"; decode["00010"] = "C"; decode["00011"] = "D"; decode["00100"] = "E"; decode["00101"] = "F"; decode["00110"] = "G"; decode["00111"] = "H"; decode["01000"] = "I"; decode["01001"] = "J"; decode["01010"] = "K"; decode["01011"] = "L"; decode["01100"] = "M"; decode["01101"] = "N"; decode["01110"] = "O"; decode["01111"] = "P"; decode["10000"] = "Q"; decode["10001"] = "R"; decode["10010"] = "S"; decode["10011"] = "T"; decode["10100"] = "U"; decode["10101"] = "V"; decode["10110"] = "W"; decode["10111"] = "X"; decode["11000"] = "Y"; decode["11001"] = "Z"; decode["11010"] = " "; decode["11011"] = "."; decode["11100"] = ","; decode["11101"] = "-"; decode["11110"] = "'"; decode["11111"] = "?"; while (getline(cin, str)) { string enc = ""; for (int i = 0; i < str.size(); i++) { enc += encode[str.substr(i, 1)]; } enc += "0000"; string dec = ""; for (int i = 0; i + 5 < enc.size(); i += 5) { dec += decode[enc.substr(i, 5)]; } cout << dec << endl; } return 0; }
#include <iostream> #include <map> #include <string> using namespace std; int main() { string str; map<string, string> encode; map<string, string> decode; encode[" "] = "101"; encode["'"] = "000000"; encode[","] = "000011"; encode["-"] = "10010001"; encode["."] = "010001"; encode["?"] = "000001"; encode["A"] = "100101"; encode["B"] = "10011010"; encode["C"] = "0101"; encode["D"] = "0001"; encode["E"] = "110"; encode["F"] = "01001"; encode["G"] = "10011011"; encode["H"] = "010000"; encode["I"] = "0111"; encode["J"] = "10011000"; encode["K"] = "0110"; encode["L"] = "00100"; encode["M"] = "10011001"; encode["N"] = "10011110"; encode["O"] = "00101"; encode["P"] = "111"; encode["Q"] = "10011111"; encode["R"] = "1000"; encode["S"] = "00110"; encode["T"] = "00111"; encode["U"] = "10011100"; encode["V"] = "10011101"; encode["W"] = "000010"; encode["X"] = "10010010"; encode["Y"] = "10010011"; encode["Z"] = "10010000"; decode["00000"] = "A"; decode["00001"] = "B"; decode["00010"] = "C"; decode["00011"] = "D"; decode["00100"] = "E"; decode["00101"] = "F"; decode["00110"] = "G"; decode["00111"] = "H"; decode["01000"] = "I"; decode["01001"] = "J"; decode["01010"] = "K"; decode["01011"] = "L"; decode["01100"] = "M"; decode["01101"] = "N"; decode["01110"] = "O"; decode["01111"] = "P"; decode["10000"] = "Q"; decode["10001"] = "R"; decode["10010"] = "S"; decode["10011"] = "T"; decode["10100"] = "U"; decode["10101"] = "V"; decode["10110"] = "W"; decode["10111"] = "X"; decode["11000"] = "Y"; decode["11001"] = "Z"; decode["11010"] = " "; decode["11011"] = "."; decode["11100"] = ","; decode["11101"] = "-"; decode["11110"] = "'"; decode["11111"] = "?"; while (getline(cin, str)) { string enc = ""; for (int i = 0; i < str.size(); i++) { enc += encode[str.substr(i, 1)]; } enc += "0000"; string dec = ""; for (int i = 0; i + 5 <= enc.size(); i += 5) { dec += decode[enc.substr(i, 5)]; } cout << dec << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
848
2
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define foreach(c, i) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) map<char, string> m; map<string, char> mm; inline char i2c(int i) { return '0' + i; } string i2bs(int a) { string ret; while (a > 0) { ret += i2c(a % 2); a /= 2; } reverse(ret.begin(), ret.end()); while (ret.size() < 5) ret = '0' + ret; return ret; } void init() { const string s[] = { "101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"}; const char c[] = {' ', '\'', ',', '-', '.', '?'}; const char cc[] = {' ', '.', ',', '-', '\'', '?'}; const int sn = sizeof(s) / sizeof(string); const int cn = sizeof(c) / sizeof(char); rep(i, sn) { if (i < cn) m.insert(make_pair(c[i], s[i])); else m.insert(make_pair('A' + (i - cn), s[i])); if (i < 26) mm.insert(make_pair(i2bs(i), 'A' + i)); else mm.insert(make_pair(i2bs(i), c[i - 26])); } } int main() { init(); string in; while (getline(cin, in)) { string tmp; rep(i, in.size()) tmp += m[in[i]]; while (tmp.size() % 5 != 0) tmp += '0'; // cout << tmp << endl; string out; for (int i = 0; i < tmp.size(); i += 5) { out += mm[tmp.substr(i, 5)]; } cout << out << endl; } return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define foreach(c, i) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) map<char, string> m; map<string, char> mm; inline char i2c(int i) { return '0' + i; } string i2bs(int a) { string ret; while (a > 0) { ret += i2c(a % 2); a /= 2; } reverse(ret.begin(), ret.end()); while (ret.size() < 5) ret = '0' + ret; return ret; } void init() { const string s[] = { "101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"}; const char c[] = {' ', '\'', ',', '-', '.', '?'}; const char cc[] = {' ', '.', ',', '-', '\'', '?'}; const int sn = sizeof(s) / sizeof(string); const int cn = sizeof(c) / sizeof(char); rep(i, sn) { if (i < cn) m.insert(make_pair(c[i], s[i])); else m.insert(make_pair('A' + (i - cn), s[i])); if (i < 26) mm.insert(make_pair(i2bs(i), 'A' + i)); else mm.insert(make_pair(i2bs(i), cc[i - 26])); } } int main() { init(); string in; while (getline(cin, in)) { string tmp; rep(i, in.size()) tmp += m[in[i]]; while (tmp.size() % 5 != 0) tmp += '0'; string out; for (int i = 0; i < tmp.size(); i += 5) { // cout << tmp.substr(i,5) << " "; out += mm[tmp.substr(i, 5)]; } // puts(""); cout << out << endl; } return 0; }
[["-", 3, 4, 0, 2, 3, 4, 0, 69, 28, 22], ["+", 3, 4, 0, 2, 3, 4, 0, 69, 28, 22]]
1
602
2
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <sstream> #include <string> using namespace std; string mkzero(int len) { char str[80]; sprintf(str, "%0*d", len, 0); return string(str); } int main() { const char *fromA = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char *toA[] = { "101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "1001111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000", ""}; const char *fromB[] = {"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111", ""}; const char *toB = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"; map<char, string> enc; for (int i = 0, len = strlen(fromA); i < len; i++) { enc.insert(make_pair(fromA[i], string(toA[i]))); } map<string, char> dec; for (int i = 0, len = strlen(toB); i < len; i++) { dec.insert(make_pair(string(fromB[i]), toB[i])); } #if 0 for(map<char, string>::const_iterator it = enc.begin(); it != enc.end(); ++it) { cerr << it->first << " -> " << it->second << endl; } for(map<string, char>::const_iterator it = dec.begin(); it != dec.end(); ++it) { cerr << it->first << " -> " << it->second << endl; } #endif for (string line; getline(cin, line);) { ostringstream ss; for (int i = 0; i < (int)line.length(); i++) ss << enc[line[i]]; if (ss.str().size() % 5 > 0) ss << mkzero(5 - ss.str().size() % 5); for (int i = 0; i < (int)ss.str().size() / 5; i++) { cout << dec[ss.str().substr(5 * i, 5)]; } cout << endl; } }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <sstream> #include <string> using namespace std; string mkzero(int len) { char str[80]; sprintf(str, "%0*d", len, 0); return string(str); } int main() { const char *fromA = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const char *toA[] = { "101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000", ""}; const char *fromB[] = {"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111", ""}; const char *toB = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"; map<char, string> enc; for (int i = 0, len = strlen(fromA); i < len; i++) { enc.insert(make_pair(fromA[i], string(toA[i]))); } map<string, char> dec; for (int i = 0, len = strlen(toB); i < len; i++) { dec.insert(make_pair(string(fromB[i]), toB[i])); } #if 0 for(map<char, string>::const_iterator it = enc.begin(); it != enc.end(); ++it) { cerr << it->first << " -> " << it->second << endl; } for(map<string, char>::const_iterator it = dec.begin(); it != dec.end(); ++it) { cerr << it->first << " -> " << it->second << endl; } #endif for (string line; getline(cin, line);) { ostringstream ss; for (int i = 0; i < (int)line.length(); i++) ss << enc[line[i]]; if (ss.str().size() % 5 > 0) ss << mkzero(5 - ss.str().size() % 5); for (int i = 0; i < (int)ss.str().size() / 5; i++) { cout << dec[ss.str().substr(5 * i, 5)]; } cout << endl; } }
[["-", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6], ["+", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6]]
1
694
2
#include <iostream> #include <string> using namespace std; char c1[32] = {' ', '\'', ',', '-', '.', '?', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; string s1[32] = {"101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "1001111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"}; string s2[32] = {"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"}; char c2[32] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '.', ',', '-', '\'', '?'}; void solve() { string s; while (getline(cin, s)) { string binary; for (int i = 0; i < s.size(); ++i) { for (int j = 0; j < 32; ++j) { if (s[i] == c1[j]) { binary += s1[j]; } } } while (binary.size() % 5 != 0) { binary += '0'; } string ans; for (int i = 0; i < binary.size(); i += 5) { string temp; for (int j = 0; j < 5; ++j) { temp += binary[i + j]; } for (int j = 0; j < 32; ++j) { if (temp == s2[j]) { ans += c2[j]; } } } cout << ans << endl; } } int main() { solve(); return (0); }
#include <iostream> #include <string> using namespace std; char c1[32] = {' ', '\'', ',', '-', '.', '?', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; string s1[32] = {"101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"}; string s2[32] = {"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"}; char c2[32] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '.', ',', '-', '\'', '?'}; void solve() { string s; while (getline(cin, s)) { string binary; for (int i = 0; i < s.size(); ++i) { for (int j = 0; j < 32; ++j) { if (s[i] == c1[j]) { binary += s1[j]; } } } while (binary.size() % 5) { binary += '0'; } string ans; for (int i = 0; i < binary.size(); i += 5) { string temp; for (int j = 0; j < 5; ++j) { temp += binary[i + j]; } for (int j = 0; j < 32; ++j) { if (temp == s2[j]) { ans += c2[j]; } } } cout << ans << endl; } } int main() { solve(); return (0); }
[["-", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6], ["+", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 79], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 12, 13]]
1
759
4
#include <iostream> #include <map> using namespace std; map<char, string> t; void make_table() { t[' '] = "101"; t['\''] = "000000"; t[','] = "000011"; t['-'] = "10010001"; t['.'] = "010001"; t['?'] = "000001"; t['A'] = "100101"; t['B'] = "10011010"; t['C'] = "0101"; t['D'] = "0001"; t['E'] = "110"; t['F'] = "01001"; t['G'] = "10011011"; t['H'] = "010000"; t['I'] = "0111"; t['J'] = "10011000"; t['K'] = "0110"; t['L'] = "00100"; t['M'] = "1001100"; t['N'] = "10011110"; t['O'] = "00101"; t['P'] = "111"; t['Q'] = "10011111"; t['R'] = "1000"; t['S'] = "00110"; t['T'] = "00111"; t['U'] = "10011100"; t['V'] = "10011101"; t['W'] = "000010"; t['X'] = "10010010"; t['Y'] = "10010011"; t['Z'] = "10010000"; } char ch_table[] = {' ', '.', ',', '-', '\'', '?'}; char s2ch(string str) { int num = 0; for (int i = 0; i < 5; i++) { num *= 2; num += str[i] - '0'; } if (num <= 25) return 'A' + num; return ch_table[num - 26]; } int main() { string str, A; make_table(); while (getline(cin, str)) { A = ""; for (int i = 0; i < (int)str.size(); i++) { A += t[str[i]]; } while (A.size() % 5 != 0) A += "0"; for (int i = 0; i < (int)A.size(); i += 5) { // cout<<A.substr(i,5)<<" "; cout << s2ch(A.substr(i, 5)); } cout << endl; } return 0; }
#include <iostream> #include <map> using namespace std; map<char, string> t; void make_table() { t[' '] = "101"; t['\''] = "000000"; t[','] = "000011"; t['-'] = "10010001"; t['.'] = "010001"; t['?'] = "000001"; t['A'] = "100101"; t['B'] = "10011010"; t['C'] = "0101"; t['D'] = "0001"; t['E'] = "110"; t['F'] = "01001"; t['G'] = "10011011"; t['H'] = "010000"; t['I'] = "0111"; t['J'] = "10011000"; t['K'] = "0110"; t['L'] = "00100"; t['M'] = "10011001"; t['N'] = "10011110"; t['O'] = "00101"; t['P'] = "111"; t['Q'] = "10011111"; t['R'] = "1000"; t['S'] = "00110"; t['T'] = "00111"; t['U'] = "10011100"; t['V'] = "10011101"; t['W'] = "000010"; t['X'] = "10010010"; t['Y'] = "10010011"; t['Z'] = "10010000"; } char ch_table[] = {' ', '.', ',', '-', '\'', '?'}; char s2ch(string str) { int num = 0; for (int i = 0; i < 5; i++) { num *= 2; num += str[i] - '0'; } if (num <= 25) return 'A' + num; return ch_table[num - 26]; } int main() { string str, A; make_table(); while (getline(cin, str)) { A = ""; for (int i = 0; i < (int)str.size(); i++) { A += t[str[i]]; } while (A.size() % 5 != 0) A += "0"; for (int i = 0; i < (int)A.size(); i += 5) { // cout<<A.substr(i,5)<<" "; cout << s2ch(A.substr(i, 5)); } cout << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 11, 12, 5, 0, 6]]
1
598
2
def main(input = STDIN) plane = {" " => "101", "'" => "000000", "," => "000011", "-" => "10010001", "." => "010001", "?" => "000001", "A" => "100101", "B" => "10011010", "C" => "0101", "D" => "0001", "E" => "110", "F" => "01001", "G" => "10011011", "H" => "010000", "I" => "0111", "J" => "10011000", "K" => "0110", "L" => "00100", "M" => "10011001", "N" => "10011110", "O" => "00101", "P" => "111", "Q" => "10011111", "R" => "1000", "S" => "00110", "T" => "00111", "U" => "10011100", "V" => "10011101", "W" => "000010", "X" => "10010010", "Y" => "10010011", "Z" => "10010000"} code = ["A"] for i in 1..25 code[i] = code[i - 1].next end code.push " ", ".", ",", "-", "'", "?" while text = input.gets output = [] coded = text.chomp.split(//).map{|char|plane[char]}.join coded << "0" * (-(coded.size + 1) % 5) for i in 0..coded.size / 5 output << code[coded.slice(i * 5, 5).to_i(2)] end puts output.join end end main
def main(input = STDIN) plane = {" " => "101", "'" => "000000", "," => "000011", "-" => "10010001", "." => "010001", "?" => "000001", "A" => "100101", "B" => "10011010", "C" => "0101", "D" => "0001", "E" => "110", "F" => "01001", "G" => "10011011", "H" => "010000", "I" => "0111", "J" => "10011000", "K" => "0110", "L" => "00100", "M" => "10011001", "N" => "10011110", "O" => "00101", "P" => "111", "Q" => "10011111", "R" => "1000", "S" => "00110", "T" => "00111", "U" => "10011100", "V" => "10011101", "W" => "000010", "X" => "10010010", "Y" => "10010011", "Z" => "10010000"} code = ["A"] for i in 1..25 code[i] = code[i - 1].next end code.push " ", ".", ",", "-", "'", "?" while text = input.gets output = [] coded = text.chomp.split(//).map{|char|plane[char]}.join coded << "0" * (-coded.size % 5) for i in 0...coded.size / 5 output << code[coded.slice(i * 5, 5).to_i(2)] end puts output.join end end main
[["-", 12, 739, 0, 738, 31, 748, 439, 739, 0, 24], ["-", 0, 738, 31, 748, 439, 739, 0, 738, 17, 72], ["-", 0, 738, 31, 748, 439, 739, 0, 738, 12, 612], ["-", 12, 739, 0, 738, 31, 748, 439, 739, 0, 25], ["-", 8, 170, 0, 88, 51, 267, 0, 475, 17, 757], ["+", 8, 170, 0, 88, 51, 267, 0, 475, 17, 389]]
4
409
6
code_a = Hash[ *%w( ' 000000 , 000011 - 10010001 . 010001 ? 000001 A 100101 B 10011010 C 0101 D 0001 E 110 F 01001 G 10011011 H 010000 I 0111 J 10011000 K 0110 L 00100 M 10011001 N 10011110 O 00101 P 111 Q 10011111 R 1000 S 00110 T 00111 U 10011100 V 10011101 W 000010 X 10010010 Y 10010011 Z 10010000 )] code_a[' '] = '101' code_b = Hash[*%w( 11011 . 11100 , 11101 - 11110 ' 11111 ? )] (?A..?Z).each{|c| code_b["%05b" % (c.ord - ?A.ord)] = c } code_b['11010'] = " " while gets puts $_ .chomp .each_char .map{|c| code_a[c]} .join .scan(/.{1,5}/) .map{|s| code_b[?0 * (5-s.size) + s]} .join end
code_a = Hash[ *%w( ' 000000 , 000011 - 10010001 . 010001 ? 000001 A 100101 B 10011010 C 0101 D 0001 E 110 F 01001 G 10011011 H 010000 I 0111 J 10011000 K 0110 L 00100 M 10011001 N 10011110 O 00101 P 111 Q 10011111 R 1000 S 00110 T 00111 U 10011100 V 10011101 W 000010 X 10010010 Y 10010011 Z 10010000 )] code_a[' '] = '101' code_b = Hash[*%w( 11011 . 11100 , 11101 - 11110 ' 11111 ? )] (?A..?Z).each{|c| code_b["%05b" % (c.ord - ?A.ord)] = c } code_b['11010'] = " " while gets puts $_ .chomp .each_char .map{|c| code_a[c]} .join .scan(/.{1,5}/) .map{|s| code_b[s + ?0 * (5 - s.size)]} .join end
[["+", 196, 196, 8, 734, 0, 742, 0, 738, 31, 22], ["+", 196, 196, 8, 734, 0, 742, 0, 738, 17, 72], ["-", 196, 196, 8, 734, 0, 742, 0, 738, 17, 72], ["-", 196, 196, 8, 734, 0, 742, 0, 738, 12, 22]]
4
190
4
words = [" ", "\'", ",", "-", ".", "?"] words += %{ABCDEFGHIJKLMNOPQRSTUVWXYZ}.split("") code = %w{101 000000 000011 10010001 010001 000001 100101 10011010 0101 0001 110 01001 10011011 010000 0111 10011000 0110 00100 10011001 10011110 00101 111 10011111 1000 00110 00111 10011100 10011101 000010 10010010 10010011 10010000} n_code = %w{11010 11110 11100 11101 11011 11111 00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001} while gets s = "" $_.split("").each do |w| s += code[words.find_index(w)] end sz = s.size%5 s += "0"*((5-sz)%5) ret = "" (s.size/5).times do |i| ret += words[n_code.find_index(s[i*5,5])] end puts ret end
words = [" ", "\'", ",", "-", ".", "?"] words += %{ABCDEFGHIJKLMNOPQRSTUVWXYZ}.split("") code = %w{101 000000 000011 10010001 010001 000001 100101 10011010 0101 0001 110 01001 10011011 010000 0111 10011000 0110 00100 10011001 10011110 00101 111 10011111 1000 00110 00111 10011100 10011101 000010 10010010 10010011 10010000} n_code = %w{11010 11110 11100 11101 11011 11111 00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001} while gets s = "" $_.chomp.split("").each do |w| s += code[words.find_index(w)] end sz = s.size%5 s += "0"*((5-sz)%5) ret = "" (s.size/5).times do |i| ret += words[n_code.find_index(s[i*5,5])] end puts ret end
[["+", 8, 170, 0, 652, 486, 652, 486, 652, 735, 22], ["+", 0, 89, 8, 170, 0, 652, 486, 652, 17, 131]]
4
202
2
mp = {} mp[" "] = "101" mp["'"] = "000000" mp[","] = "000011" mp["-"] = "10010001" mp["."] = "010001" mp["?"] = "000001" mp["A"] = "100101" mp["B"] = "10011010" mp["C"] = "0101" mp["D"] = "0001" mp["E"]="110" mp["F"]="01001" mp["G"]="10011011" mp["H"]="010000" mp["I"]="0111" mp["J"]="10011000" mp["K"]="0110" mp["L"]="00100" mp["N"]="10011001" mp["M"]="10011110" mp["O"]="00101" mp["P"]="111" mp["Q"]="10011111" mp["R"]="1000" mp["S"]="00110" mp["T"]="00111" mp["U"]="10011100" mp["V"]="10011101" mp["W"]="000010" mp["X"]="10010010" mp["Y"]="10010011" mp["Z"]="10010000" gyaku = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?" while s=gets s=s.chomp t="" for i in 0...s.length t+=mp[s[i]] end n = t.length t += "0"*((5-n%5)%5) n = t.length res = "" for i in 0...(n/5) beg = i*5 id = 0 for j in 0...5 id*=2 id+=(t[beg+j]=="0" ? 0 : 1) end res += gyaku[id] end puts res end
mp = {} mp[" "] = "101" mp["'"] = "000000" mp[","] = "000011" mp["-"] = "10010001" mp["."] = "010001" mp["?"] = "000001" mp["A"] = "100101" mp["B"] = "10011010" mp["C"] = "0101" mp["D"] = "0001" mp["E"]="110" mp["F"]="01001" mp["G"]="10011011" mp["H"]="010000" mp["I"]="0111" mp["J"]="10011000" mp["K"]="0110" mp["L"]="00100" mp["M"]="10011001" mp["N"]="10011110" mp["O"]="00101" mp["P"]="111" mp["Q"]="10011111" mp["R"]="1000" mp["S"]="00110" mp["T"]="00111" mp["U"]="10011100" mp["V"]="10011101" mp["W"]="000010" mp["X"]="10010010" mp["Y"]="10010011" mp["Z"]="10010000" gyaku = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?" while s=gets s=s.chomp t="" for i in 0...s.length t+=mp[s[i]] end n = t.length t += "0"*((5-n%5)%5) n = t.length res = "" for i in 0...(n/5) beg = i*5 id = 0 for j in 0...5 id*=2 id+=(t[beg+j]=="0" ? 0 : 1) end res += gyaku[id] end puts res end
[["-", 0, 493, 0, 662, 31, 742, 0, 557, 0, 6], ["+", 0, 493, 0, 662, 31, 742, 0, 557, 0, 6]]
4
447
4
T = { ' ' => '101', ?' => '000000', ?, => '000011', ?- => '10010001', ?. => '010001', ?? => '000001', ?A => '100101', ?B => '10011010', ?C => '0101', ?D => '0001', ?E => '110', ?F => '01001', ?G => '10011011', ?H => '010000', ?I => '0111', ?J => '10011000', ?K => '0110', ?L => '00100', ?M => '10011001', ?N => '10011110', ?O => '00101', ?P => '111', ?Q => '10011111', ?R => '1000', ?S => '00110', ?T => '00111', ?U => '10011100', ?V => '10011101', ?W => '000010', ?X => '10010010', ?Y => '10010011', ?Z => '10010000', }.freeze S = { 0b00000 => ?A, 0b00001 => ?B, 0b00010 => ?C, 0b00011 => ?D, 0b00100 => ?E, 0b00101 => ?F, 0b00110 => ?G, 0b00111 => ?H, 0b01000 => ?I, 0b01001 => ?J, 0b01010 => ?K, 0b01011 => ?L, 0b01100 => ?M, 0b01101 => ?N, 0b01110 => ?O, 0b01111 => ?P, 0b10000 => ?Q, 0b10001 => ?R, 0b10010 => ?S, 0b10011 => ?T, 0b10100 => ?U, 0b10101 => ?V, 0b10110 => ?W, 0b10111 => ?X, 0b11000 => ?Y, 0b11001 => ?Z, 0b11010 => ' ', 0b11011 => ?., 0b11100 => ?,, 0b11101 => ?-, 0b11110 => ?', 0b11111 => ??, }.freeze $<.each_line do |l| s = '' l.chomp.each_char {|c| s << T[c] } s << ?0 * (5 - s.size % 5) puts s.each_char.each_slice(5).map {|a| S[a.join.to_i 2] }.join end
T = { ' ' => '101', ?' => '000000', ?, => '000011', ?- => '10010001', ?. => '010001', ?? => '000001', ?A => '100101', ?B => '10011010', ?C => '0101', ?D => '0001', ?E => '110', ?F => '01001', ?G => '10011011', ?H => '010000', ?I => '0111', ?J => '10011000', ?K => '0110', ?L => '00100', ?M => '10011001', ?N => '10011110', ?O => '00101', ?P => '111', ?Q => '10011111', ?R => '1000', ?S => '00110', ?T => '00111', ?U => '10011100', ?V => '10011101', ?W => '000010', ?X => '10010010', ?Y => '10010011', ?Z => '10010000', }.freeze S = { 0b00000 => ?A, 0b00001 => ?B, 0b00010 => ?C, 0b00011 => ?D, 0b00100 => ?E, 0b00101 => ?F, 0b00110 => ?G, 0b00111 => ?H, 0b01000 => ?I, 0b01001 => ?J, 0b01010 => ?K, 0b01011 => ?L, 0b01100 => ?M, 0b01101 => ?N, 0b01110 => ?O, 0b01111 => ?P, 0b10000 => ?Q, 0b10001 => ?R, 0b10010 => ?S, 0b10011 => ?T, 0b10100 => ?U, 0b10101 => ?V, 0b10110 => ?W, 0b10111 => ?X, 0b11000 => ?Y, 0b11001 => ?Z, 0b11010 => ' ', 0b11011 => ?., 0b11100 => ?,, 0b11101 => ?-, 0b11110 => ?', 0b11111 => ??, }.freeze $<.each_line do |l| s = '' l.chomp.each_char {|c| s << T[c] } s << ?0 * ((5 - s.size) % 5) puts s.each_char.each_slice(5).map {|a| S[a.join.to_i 2] }.join end
[["+", 12, 738, 12, 739, 0, 738, 31, 739, 0, 24], ["+", 12, 738, 12, 739, 0, 738, 31, 739, 0, 25]]
4
404
2
class String @@encode = {} @@decode = {} def encode res = split('').map{ |c| @@encode[c] }.join res + '0' * (5 - res.size % 5) % 5 end def decode scan(/.{5}/).map{ |s| @@decode[s] }.join end @@encode[" "] = "101" @@encode["'"] = "000000" @@encode[","] = "000011" @@encode["-"] = "10010001" @@encode["."] = "010001" @@encode["?"] = "000001" @@encode["A"] = "100101" @@encode["B"] = "10011010" @@encode["C"] = "0101" @@encode["D"] = "0001" @@encode["E"] = "110" @@encode["F"] = "01001" @@encode["G"] = "10011011" @@encode["H"] = "010000" @@encode["I"] = "0111" @@encode["J"] = "10011000" @@encode["K"] = "0110" @@encode["L"] = "00100" @@encode["M"] = "10011001" @@encode["N"] = "10011110" @@encode["O"] = "00101" @@encode["P"] = "111" @@encode["Q"] = "10011111" @@encode["R"] = "1000" @@encode["S"] = "00110" @@encode["T"] = "00111" @@encode["U"] = "10011100" @@encode["V"] = "10011101" @@encode["W"] = "000010" @@encode["X"] = "10010010" @@encode["Y"] = "10010011" @@encode["Z"] = "10010000" @@decode["00000"] = "A" @@decode["00001"] = "B" @@decode["00010"] = "C" @@decode["00011"] = "D" @@decode["00100"] = "E" @@decode["00101"] = "F" @@decode["00110"] = "G" @@decode["00111"] = "H" @@decode["01000"] = "I" @@decode["01001"] = "J" @@decode["01010"] = "K" @@decode["01011"] = "L" @@decode["01100"] = "M" @@decode["01101"] = "N" @@decode["01110"] = "O" @@decode["01111"] = "P" @@decode["10000"] = "Q" @@decode["10001"] = "R" @@decode["10010"] = "S" @@decode["10011"] = "T" @@decode["10100"] = "U" @@decode["10101"] = "V" @@decode["10110"] = "W" @@decode["10111"] = "X" @@decode["11000"] = "Y" @@decode["11001"] = "Z" @@decode["11010"] = " " @@decode["11011"] = "." @@decode["11100"] = "," @@decode["11101"] = "-" @@decode["11110"] = "'" @@decode["11111"] = "?" end while line = gets puts line.encode.decode end
class String @@encode = {} @@decode = {} def encode res = split('').map{ |c| @@encode[c] }.join res + '0' * ((5 - res.size % 5) % 5) end def decode scan(/.{5}/).map{ |s| @@decode[s] }.join end @@encode[" "] = "101" @@encode["'"] = "000000" @@encode[","] = "000011" @@encode["-"] = "10010001" @@encode["."] = "010001" @@encode["?"] = "000001" @@encode["A"] = "100101" @@encode["B"] = "10011010" @@encode["C"] = "0101" @@encode["D"] = "0001" @@encode["E"] = "110" @@encode["F"] = "01001" @@encode["G"] = "10011011" @@encode["H"] = "010000" @@encode["I"] = "0111" @@encode["J"] = "10011000" @@encode["K"] = "0110" @@encode["L"] = "00100" @@encode["M"] = "10011001" @@encode["N"] = "10011110" @@encode["O"] = "00101" @@encode["P"] = "111" @@encode["Q"] = "10011111" @@encode["R"] = "1000" @@encode["S"] = "00110" @@encode["T"] = "00111" @@encode["U"] = "10011100" @@encode["V"] = "10011101" @@encode["W"] = "000010" @@encode["X"] = "10010010" @@encode["Y"] = "10010011" @@encode["Z"] = "10010000" @@decode["00000"] = "A" @@decode["00001"] = "B" @@decode["00010"] = "C" @@decode["00011"] = "D" @@decode["00100"] = "E" @@decode["00101"] = "F" @@decode["00110"] = "G" @@decode["00111"] = "H" @@decode["01000"] = "I" @@decode["01001"] = "J" @@decode["01010"] = "K" @@decode["01011"] = "L" @@decode["01100"] = "M" @@decode["01101"] = "N" @@decode["01110"] = "O" @@decode["01111"] = "P" @@decode["10000"] = "Q" @@decode["10001"] = "R" @@decode["10010"] = "S" @@decode["10011"] = "T" @@decode["10100"] = "U" @@decode["10101"] = "V" @@decode["10110"] = "W" @@decode["10111"] = "X" @@decode["11000"] = "Y" @@decode["11001"] = "Z" @@decode["11010"] = " " @@decode["11011"] = "." @@decode["11100"] = "," @@decode["11101"] = "-" @@decode["11110"] = "'" @@decode["11111"] = "?" end while line = gets puts line.encode.decode end
[["+", 12, 738, 12, 739, 0, 738, 31, 739, 0, 24], ["+", 8, 736, 0, 738, 12, 738, 12, 739, 0, 25]]
4
724
2
dic1 = {" ":"101", "'":"000000", ",":"000011", "-":"10010001", ".":"010001", "?":"000001", "A":"100101", "B":"10011010", "C":"0101", "D":"0101", "E":"110", "F":"01001", "G":"10011011", "H":"010000", "I":"0111", "J":"10011000", "K":"0110", "L":"00100", "M":"10011001", "N":"10011110", "O":"00101", "P":"111", "Q":"10011111", "R":"1000", "S":"00110", "T":"00111", "U":"10011100", "V":"10011101", "W":"000010", "X":"10010010", "Y":"10010011", "Z":"10010000"} dic2 = {"00000":"A", "00001":"B", "00010":"C", "00011":"D", "00100":"E", "00101":"F", "00110":"G", "00111":"H", "01000":"I", "01001":"J", "01010":"K", "01011":"L", "01100":"M", "01101":"N", "01110":"O", "01111":"P", "10000":"Q", "10001":"R", "10010":"S", "10011":"T", "10100":"U", "10101":"V", "10110":"W", "10111":"X", "11000":"Y", "11001":"Z", "11010":" ", "11011":".", "11100":",", "11101":"-", "11110":"'", "11111":"?"} def to_digit(ss): ret = "" for s in ss: ret += dic1[s] return ret def to_alpha(digit): ret = "" ind = 0 end = len(digit) while ind + 5 < end: ret += dic2[digit[ind:ind + 5]] ind += 5 if digit[ind:]: ret += dic2[digit[ind:] + "0" * (5 - end + ind)] return ret while True: try: print(to_alpha(to_digit(input()))) except EOFError: break
dic1 = {" ":"101", "'":"000000", ",":"000011", "-":"10010001", ".":"010001", "?":"000001", "A":"100101", "B":"10011010", "C":"0101", "D":"0001", "E":"110", "F":"01001", "G":"10011011", "H":"010000", "I":"0111", "J":"10011000", "K":"0110", "L":"00100", "M":"10011001", "N":"10011110", "O":"00101", "P":"111", "Q":"10011111", "R":"1000", "S":"00110", "T":"00111", "U":"10011100", "V":"10011101", "W":"000010", "X":"10010010", "Y":"10010011", "Z":"10010000"} dic2 = {"00000":"A", "00001":"B", "00010":"C", "00011":"D", "00100":"E", "00101":"F", "00110":"G", "00111":"H", "01000":"I", "01001":"J", "01010":"K", "01011":"L", "01100":"M", "01101":"N", "01110":"O", "01111":"P", "10000":"Q", "10001":"R", "10010":"S", "10011":"T", "10100":"U", "10101":"V", "10110":"W", "10111":"X", "11000":"Y", "11001":"Z", "11010":" ", "11011":".", "11100":",", "11101":"-", "11110":"'", "11111":"?"} def to_digit(ss): ret = "" for s in ss: ret += dic1[s] return ret def to_alpha(digit): ret = "" ind = 0 end = len(digit) while ind + 5 < end: ret += dic2[digit[ind:ind + 5]] ind += 5 if digit[ind:]: ret += dic2[digit[ind:] + "0" * (5 - end + ind)] return ret while True: try: print(to_alpha(to_digit(input()))) except EOFError: break
[["-", 0, 662, 12, 680, 0, 569, 51, 557, 0, 6], ["+", 0, 662, 12, 680, 0, 569, 51, 557, 0, 6]]
5
635
2
encode = { ' ':'101', "'":'000000', ',':'000011', '-':'10010001', '.':'010001', '?':'000001', 'A':'100101', 'B':'10011010', 'C':'0101', 'D':'0001', 'E':'110', 'F':'01001', 'G':'10011011', 'H':'010000', 'I':'0111', 'J':'10011000', 'K':'0110', 'L':'00100', 'M':'10011001', 'N':'10011110', 'O':'00101', 'P':'111', 'Q':'10011111', 'R':'1000', 'S':'00110', 'T':'00111', 'U':'10011100', 'V':'10011101', 'W':'000010', 'X':'10010010', 'Y':'10010011', 'Z':'10010000'} decode = { "00000":"A", "00001":"B", "00010":"C", "00011":"D", "00100":"E", "00101":"F", "00110":"G", "00111":"H", "01000":"I", "01001":"J", "01010":"K", "01011":"L", "01100":"M", "01101":"N", "01110":"O", "01111":"P", "10000":"Q", "10001":"R", "10010":"S", "10011":"T", "10100":"U", "10101":"V", "10110":"W", "10111":"X", "11000":"Y", "11001":"Z", "11010":" ", "11011":".", "11100":",", "11101":"-", "11110":"'", "11111":"?"} while True: try: string = input() except EOFError: break # encode e, ans = "", "" for s in string: e += encode[s] tmp = [] while len(e) > 4: tmp.append(e[0:5]) e = e[5:] if len(e) != 0: e += '0' * (5 - len(e)) tmp.append(e) print(tmp) # decode for s in tmp: ans += decode[s] print(ans)
encode = { ' ':'101', "'":'000000', ',':'000011', '-':'10010001', '.':'010001', '?':'000001', 'A':'100101', 'B':'10011010', 'C':'0101', 'D':'0001', 'E':'110', 'F':'01001', 'G':'10011011', 'H':'010000', 'I':'0111', 'J':'10011000', 'K':'0110', 'L':'00100', 'M':'10011001', 'N':'10011110', 'O':'00101', 'P':'111', 'Q':'10011111', 'R':'1000', 'S':'00110', 'T':'00111', 'U':'10011100', 'V':'10011101', 'W':'000010', 'X':'10010010', 'Y':'10010011', 'Z':'10010000'} decode = { "00000":"A", "00001":"B", "00010":"C", "00011":"D", "00100":"E", "00101":"F", "00110":"G", "00111":"H", "01000":"I", "01001":"J", "01010":"K", "01011":"L", "01100":"M", "01101":"N", "01110":"O", "01111":"P", "10000":"Q", "10001":"R", "10010":"S", "10011":"T", "10100":"U", "10101":"V", "10110":"W", "10111":"X", "11000":"Y", "11001":"Z", "11010":" ", "11011":".", "11100":",", "11101":"-", "11110":"'", "11111":"?"} while True: try: string = input() except EOFError: break e, ans = "", "" for s in string: e += encode[s] tmp = [] while len(e) > 4: tmp.append(e[0:5]) e = e[5:] if len(e) != 0: e += '0' * (5 - len(e)) tmp.append(e) for s in tmp: ans += decode[s] print(ans)
[["-", 0, 52, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
631
4
import sys A=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ" B="101 000000 000011 10010001 010001 000001 100101 10011010 "\ "0101 0001 110 01001 10011011 010000 0111 10011000 "\ "0110 00100 10011001 10011110 00101 111 10011111 1000 "\ "00110 00111 10011100 10011101 000010 10010010 10010011 10010000".split() C="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?" d1={} for i in range(26):d1[A[i]]=B[i] for s in sys.stdin: x="" for c in s[:-1]:x+=d1[c] x+="0"*(-len(x)%5) s="" for i in range(0,len(x),5):s+=C[int(x[i:i+5],2)] print(s)
import sys A=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ" B="101 000000 000011 10010001 010001 000001 100101 10011010 "\ "0101 0001 110 01001 10011011 010000 0111 10011000 "\ "0110 00100 10011001 10011110 00101 111 10011111 1000 "\ "00110 00111 10011100 10011101 000010 10010010 10010011 10010000".split() C="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?" d1={} for i in range(32):d1[A[i]]=B[i] for s in sys.stdin: x="" for c in s[:-1]:x+=d1[c] x+="0"*(-len(x)%5) s="" for i in range(0,len(x),5):s+=C[int(x[i:i+5],2)] print(s)
[["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612]]
5
140
2
<?php class Node { public $left; public $right; public $value; public $largest; public function __construct($value) { $this->value = $value; } public function max_value() { if ($this->largest !== null) { return $this->largest; } if (is_null($this->left) && is_null($this->right)) { return $this->value; } $left = is_null($this->left) ? -1 : $this->left->max_value(); $right = is_null($this->right) ? -1 : $this->right->max_value(); return $this->largest = $this->value + max($left, $right); } } $diamond = array(); while ($line = trim(fgets(STDIN))) { $diamond[] = explode(',', $line); } $nodes = array(); for ($i = 0; $i < count($diamond); $i++) { for ($j = 0; $j < count($diamond[$i]); $j++) { $nodes[$i][$j] = new Node($diamond[$i][$j]); } } for ($i = 0; $i < count($diamond); $i++) { for ($j = 0; $j < count($diamond[$i]); $j++) { $n = $nodes[$i][$j]; if ($i < count($diamond)/2) { $n->left = isset($nodes[$i + 1][$j]) ? $nodes[$i + 1][$j] : null; $n->right = isset($nodes[$i + 1][$j + 1]) ? $nodes[$i + 1][$j + 1] : null; } else { $n->left = isset($nodes[$i + 1][$j - 1]) ? $nodes[$i + 1][$j - 1] : null; $n->right = isset($nodes[$i + 1][$j]) ? $nodes[$i + 1][$j] : null; } } } $top = $nodes[0][0]; echo $top->max_value() . "\n";
<?php class Node { public $left; public $right; public $value; public $largest; public function __construct($value) { $this->value = $value; } public function max_value() { if ($this->largest !== null) { return $this->largest; } if (is_null($this->left) && is_null($this->right)) { return $this->value; } $left = is_null($this->left) ? -1 : $this->left->max_value(); $right = is_null($this->right) ? -1 : $this->right->max_value(); return $this->largest = $this->value + max($left, $right); } } $diamond = array(); while ($line = trim(fgets(STDIN))) { $diamond[] = explode(',', $line); } $nodes = array(); for ($i = 0; $i < count($diamond); $i++) { for ($j = 0; $j < count($diamond[$i]); $j++) { $nodes[$i][$j] = new Node($diamond[$i][$j]); } } for ($i = 0; $i < count($nodes); $i++) { for ($j = 0; $j < count($nodes[$i]); $j++) { $n = $nodes[$i][$j]; if ($i < count($diamond)/2 - 1) { $n->left = isset($nodes[$i + 1][$j]) ? $nodes[$i + 1][$j] : null; $n->right = isset($nodes[$i + 1][$j + 1]) ? $nodes[$i + 1][$j + 1] : null; } else { $n->left = isset($nodes[$i + 1][$j - 1]) ? $nodes[$i + 1][$j - 1] : null; $n->right = isset($nodes[$i + 1][$j]) ? $nodes[$i + 1][$j] : null; } } } $top = $nodes[0][0]; echo $top->max_value() . "\n";
[["-", 12, 613, 3, 3, 0, 28, 0, 606, 0, 141], ["+", 12, 613, 3, 3, 0, 28, 0, 606, 0, 141], ["-", 3, 3, 0, 28, 0, 69, 0, 606, 0, 141], ["+", 3, 3, 0, 28, 0, 69, 0, 606, 0, 141], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 612]]
6
528
6
import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().main(); } void main() { Scanner sc = new Scanner(System.in); int[][] a = new int[100][100]; int i = 0; while (sc.hasNextLine()) { String s = sc.nextLine(); String[] temp = s.split(","); // System.out.println(temp.length); for (int j = 0; j < temp.length; j++) { // System.out.print(temp[j] + " "); a[i][j] = Integer.valueOf(temp[j]); // System.out.println(a[i][j]); } // System.out.println(); i++; } int e = (i / 2) + 1; int[][] dp = new int[e][e]; int ind = 0; for (int k = 0; k < e; k++) { for (int j = 0; j < e; j++) { int min = Math.min(k + 1, (2 * e) - (k + 1)); if (k + j < e) { dp[k][j] = a[k + j][min - 1 - k]; ind = min - 1 - k; } else { dp[k][j] = a[k + j][ind]; } } } // for(int k=0;k<e;k++) { // for(int j=0;j<e;j++) { // System.out.print(dp[k][j]); // } // System.out.println(); // } for (int j = 1; j < e; j++) { dp[0][j] += dp[0][j - 1]; } for (int k = 1; k < e; k++) { dp[k][0] += dp[k - 1][0]; } for (int k = 1; k < e; k++) { for (int j = 1; j < e; j++) { dp[k][j] += Math.max(dp[k - 1][j], dp[k][j - 1]); } } System.out.println(dp[e - 1][e - 1]); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().main(); } void main() { Scanner sc = new Scanner(System.in); int[][] a = new int[100][100]; int i = 0; while (sc.hasNext()) { String s = sc.nextLine(); String[] temp = s.split(","); // System.out.println(temp.length); for (int j = 0; j < temp.length; j++) { // System.out.print(temp[j] + " "); a[i][j] = Integer.parseInt(temp[j]); // System.out.println(a[i][j]); } // System.out.println(); i++; } // System.out.println(i); int e = (i / 2) + 1; int[][] dp = new int[e][e]; int ind = 0; for (int k = 0; k < e; k++) { for (int j = 0; j < e; j++) { int min = Math.min(k + j + 1, (2 * e) - (k + j + 1)); if (k + j < e) { dp[k][j] = a[k + j][min - 1 - k]; ind = min - 1 - k; } else { dp[k][j] = a[k + j][ind]; } } } // for(int k=0;k<e;k++) { // for(int j=0;j<e;j++) { // System.out.print(dp[k][j]); // } // System.out.println(); // } for (int j = 1; j < e; j++) { dp[0][j] += dp[0][j - 1]; } for (int k = 1; k < e; k++) { dp[k][0] += dp[k - 1][0]; } for (int k = 1; k < e; k++) { for (int j = 1; j < e; j++) { dp[k][j] += Math.max(dp[k - 1][j], dp[k][j - 1]); } } System.out.println(dp[e - 1][e - 1]); } }
[["-", 8, 196, 0, 52, 15, 15, 0, 492, 141, 22], ["+", 8, 196, 0, 52, 15, 15, 0, 492, 141, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 492, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 492, 141, 22], ["+", 51, 492, 3, 4, 0, 16, 31, 16, 17, 72], ["+", 51, 492, 3, 4, 0, 16, 31, 16, 12, 22], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 17, 72], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 22]]
3
454
8
#include <stdio.h> #include <string.h> int a[110][110], n = 0, c, d[110][110]; char s[110][200]; int main() { int i, j; n = 0; while (scanf("%s", s[n]) != EOF) { c = 0; a[n][c] = 0; for (i = 0; i < strlen(s[n]); i++) { if (s[n][i] == ',') { a[n][c] /= 10; c++; a[n][c] = 0; } else { a[n][c] += s[n][i] - '0'; a[n][c] *= 10; } } a[n][c] /= 10; n++; } d[0][0] = a[0][0]; for (i = 1; i < (n + 1) / 2; i++) { c = (i >= (n + 1) / 2) ? (n - 1 - i) : i; for (j = 0; j <= c; j++) { if (i < (n + 1) / 2) { if (j == 0) d[i][j] = d[i - 1][0] + a[i][j]; else if (j == i) d[i][j] = d[i - 1][j - 1] + a[i][j]; else d[i][j] = (d[i - 1][j - 1] < d[i - 1][j]) ? d[i - 1][j] : d[i - 1][j - 1], d[i][j] += a[i][j]; } else d[i][j] = (d[i - 1][j + 1] < d[i - 1][j]) ? d[i - 1][j] : d[i - 1][j + 1], d[i][j] += a[i][j]; } } printf("%d\n", d[n - 1][0]); return 0; }
#include <stdio.h> #include <string.h> int a[110][110], n = 0, c, d[110][110]; char s[110][200]; int main() { int i, j; n = 0; while (scanf("%s", s[n]) != EOF) { c = 0; a[n][c] = 0; for (i = 0; i < strlen(s[n]); i++) { if (s[n][i] == ',') { a[n][c] /= 10; c++; a[n][c] = 0; } else { a[n][c] += s[n][i] - '0'; a[n][c] *= 10; } } a[n][c] /= 10; n++; } d[0][0] = a[0][0]; for (i = 1; i < n; i++) { c = (i >= (n + 1) / 2) ? (n - 1 - i) : i; for (j = 0; j <= c; j++) { if (i < (n + 1) / 2) { if (j == 0) d[i][j] = d[i - 1][0] + a[i][j]; else if (j == i) d[i][j] = d[i - 1][j - 1] + a[i][j]; else d[i][j] = (d[i - 1][j - 1] < d[i - 1][j]) ? d[i - 1][j] : d[i - 1][j - 1], d[i][j] += a[i][j]; } else d[i][j] = (d[i - 1][j + 1] < d[i - 1][j]) ? d[i - 1][j] : d[i - 1][j + 1], d[i][j] += a[i][j]; } } printf("%d\n", d[n - 1][0]); return 0; }
[["-", 0, 7, 15, 16, 12, 16, 31, 23, 0, 24], ["-", 15, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 15, 16, 12, 16, 31, 23, 0, 16, 12, 13], ["-", 0, 7, 15, 16, 12, 16, 31, 23, 0, 25], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 85], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
0
509
6
#include <stdio.h> char data[99][50]; int max(int x, int y) { if (x > y) { return (x); } return (y); } int judge(int n) { int i, j; int dp[100][50]; for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) { if (i <= n / 2 + 1) { dp[i][j] = data[i][j] + max(dp[i - 1][j], dp[i - 1][j - 1]); } else { if (j > (n / 2 + 1) * 2 - i) { break; } dp[i][j] = data[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]); } } } return (dp[n][1]); } int main(void) { int i, j; char g; g = 0; i = j = 1; while (scanf("%d%c", &data[i][j], &g) != EOF) { if (g == ',') { j++; g = 0; } else { data[i][j + 1] = 0; i++; data[i][0] = 0; j = 1; } } printf("%d\n", judge(i)); return (0); }
#include <stdio.h> char data[99][50]; int max(int x, int y) { if (x > y) { return (x); } return (y); } int judge(int n) { int i, j; int dp[100][50]; for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) { if (i <= n / 2 + 1) { dp[i][j] = data[i][j] + max(dp[i - 1][j], dp[i - 1][j - 1]); } else { if (j > (n / 2 + 1) * 2 - i) { break; } dp[i][j] = data[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]); } } } return (dp[n][1]); } int main(void) { int i, j; char g; g = 0; i = j = 1; while (scanf("%d%c", &data[i][j], &g) != EOF) { if (g == ',') { j++; g = 0; } else { data[i][j + 1] = 0; i++; data[i][0] = 0; j = 1; } } printf("%d\n", judge(i - 1)); return (0); }
[["+", 3, 4, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 3, 4, 0, 2, 3, 4, 0, 16, 12, 13]]
0
337
2
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (long long i = (a); i < (b); i++) #define REP(i, N) for (long long i = 0; i < (N); i++) #define ALL(s) (s).begin(), (s).end() #define fi first #define se second #define PI acos(-1.0) #define INF 1000000007 #define EPS 1e-10 typedef long long ll; typedef pair<ll, ll> P; typedef pair<double, double> PD; typedef pair<string, ll> PS; typedef vector<ll> V; string s; int n; vector<vector<int>> vvi; int maxsize = 0; int changei(string s) { int res; stringstream ss; ss << s; ss >> res; return res; } vector<int> changevi(string s) { vector<int> vi; int res; string t; REP(i, s.size()) { if (i == s.size() - 1) { t += s[i]; res = changei(t); vi.push_back(res); t.clear(); } else { if (s[i] == ',') { res = changei(t); vi.push_back(res); t.clear(); } else { t += s[i]; } } } return vi; } int dp[100][100]; int main() { while (cin >> s) { vector<int> vi = changevi(s); maxsize = max((int)(vi.size()), maxsize); vvi.push_back(vi); } dp[0][0] = vvi[0][0]; REP(i, 2 * maxsize - 1) { REP(j, vvi[i + 1].size()) { if (i <= maxsize - 1) { if (j == 0) { dp[i + 1][j] = dp[i][j] + vvi[i + 1][j]; } // else if (j == vvi[i + 1].size() - 1){ // dp[i + 1][j] = dp[i][j - 1] + vvi[i + 1][j]; //} else { dp[i + 1][j] = max(dp[i][j - 1], dp[i][j]) + vvi[i + 1][j]; } } else { dp[i + 1][j] = max(dp[i][j], dp[i][j + 1]) + vvi[i + 1][j]; } } /*REP(j, vvi[i].size()){ cout << dp[i][j] << " "; } cout << endl;*/ } // REP(i, 2 * maxsize-1){ // REP(j, vvi[i].size()){ // cout << dp[i][j] << " "; // } // cout << endl; //} cout << dp[2 * maxsize - 1 - 1][0] << endl; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (long long i = (a); i < (b); i++) #define REP(i, N) for (long long i = 0; i < (N); i++) #define ALL(s) (s).begin(), (s).end() #define fi first #define se second #define PI acos(-1.0) #define INF 1000000007 #define EPS 1e-10 typedef long long ll; typedef pair<ll, ll> P; typedef pair<double, double> PD; typedef pair<string, ll> PS; typedef vector<ll> V; string s; int n; vector<vector<int>> vvi; int maxsize = 0; int changei(string s) { int res; stringstream ss; ss << s; ss >> res; return res; } vector<int> changevi(string s) { vector<int> vi; int res; string t; REP(i, s.size()) { if (i == s.size() - 1) { t += s[i]; res = changei(t); vi.push_back(res); t.clear(); } else { if (s[i] == ',') { res = changei(t); vi.push_back(res); t.clear(); } else { t += s[i]; } } } return vi; } int dp[100][100]; int main() { while (cin >> s) { vector<int> vi = changevi(s); maxsize = max((int)(vi.size()), maxsize); vvi.push_back(vi); } dp[0][0] = vvi[0][0]; REP(i, 2 * maxsize - 1) { REP(j, vvi[i + 1].size()) { if (i + 1 <= maxsize - 1) { if (j == 0) { dp[i + 1][j] = dp[i][j] + vvi[i + 1][j]; } // else if (j == vvi[i + 1].size() - 1){ // dp[i + 1][j] = dp[i][j - 1] + vvi[i + 1][j]; //} else { dp[i + 1][j] = max(dp[i][j - 1], dp[i][j]) + vvi[i + 1][j]; } } else { dp[i + 1][j] = max(dp[i][j], dp[i][j + 1]) + vvi[i + 1][j]; } } /*REP(j, vvi[i].size()){ cout << dp[i][j] << " "; } cout << endl;*/ } // REP(i, 2 * maxsize-1){ // REP(j, vvi[i].size()){ // cout << dp[i][j] << " "; // } // cout << endl; //} cout << dp[2 * maxsize - 1 - 1][0] << endl; }
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13]]
1
551
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MOD 1000000007 #define INF (1LL << 25) // 33554432 #define PI 3.14159265359 #define EPS 1e-12 //#define int ll vector<string> split(const string &str, char sep) { vector<string> v; auto first = str.begin(); while (first != str.end()) { auto last = first; while (last != str.end() && *last != sep) ++last; v.push_back(std::string(first, last)); if (last != str.end()) ++last; first = last; } return v; } signed main(void) { string s; int ii = 0, d[105][105]; REP(i, 105) REP(j, 105) d[i][j] = -1; while (cin >> s) { vector<string> v = split(s, ','); REP(i, v.size()) { d[ii][i] = stoi(v[i]); } ii++; } int num = (ii + 1) / 2; /*REP(i, ii+1) { REP(j, num+1) { cout << d[i][j] << " "; } cout << endl; }*/ int dp[105][105]; REP(i, 105) REP(j, 105) dp[i][j] = -1; dp[0][0] = d[0][0]; FOR(i, 1, num + 1) { REP(j, i + 1) { // cout << j << " "; if (j > 0) { dp[i][j] = max(dp[i][j], d[i][j] + max(dp[i - 1][j - 1], dp[i - 1][j])); } else { dp[i][j] = max(dp[i][j], d[i][j] + dp[i - 1][j]); } // cout << d[i][j] << " " << dp[i-1][j] << " "; } } FOR(i, num + 1, ii + 1) { REP(j, 2 * num - i + 1) { // cout << j << " "; dp[i][j] = max(dp[i][j], d[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1])); } } cout << dp[ii][0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MOD 1000000007 #define INF (1LL << 25) // 33554432 #define PI 3.14159265359 #define EPS 1e-12 //#define int ll vector<string> split(const string &str, char sep) { vector<string> v; auto first = str.begin(); while (first != str.end()) { auto last = first; while (last != str.end() && *last != sep) ++last; v.push_back(std::string(first, last)); if (last != str.end()) ++last; first = last; } return v; } signed main(void) { string s; int ii = 0, d[105][105]; REP(i, 105) REP(j, 105) d[i][j] = -1; while (cin >> s) { vector<string> v = split(s, ','); REP(i, v.size()) { d[ii][i] = stoi(v[i]); } ii++; } ii--; int num = (ii + 1) / 2; /*REP(i, ii+1) { REP(j, num+1) { cout << d[i][j] << " "; } cout << endl; }*/ int dp[105][105]; REP(i, 105) REP(j, 105) dp[i][j] = -1; dp[0][0] = d[0][0]; FOR(i, 1, num + 1) { REP(j, i + 1) { // cout << j << " "; if (j > 0) { dp[i][j] = max(dp[i][j], d[i][j] + max(dp[i - 1][j - 1], dp[i - 1][j])); } else { dp[i][j] = max(dp[i][j], d[i][j] + dp[i - 1][j]); } // cout << dp[i][j] << " "; } // cout << endl; } FOR(i, num + 1, ii + 1) { REP(j, 2 * num - i + 1) { // cout << j << " "; dp[i][j] = max(dp[i][j], d[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1])); // cout << dp[i][j] << " "; } // cout << endl; } cout << dp[ii][0] << endl; return 0; }
[["+", 0, 14, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 27, 17, 68], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
570
3
#include <algorithm> #include <iostream> #include <queue> #include <vector> #define lol(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 typedef long long ll; using namespace std; vector<int> v[110]; int dp[110][110]; int main() { int n = 0, maxi = 0; string z; while (cin >> z) { z.push_back(','); int cnt = 0; lol(i, z.size()) { if (z[i] == ',') { v[n].push_back(cnt); cnt = 0; } else { cnt *= 10; cnt += z[i] - '0'; } } int tmp = v[n].size(); maxi = max(maxi, tmp); n++; } lol(i, n) lol(j, maxi) dp[i][j] = 0; lol(i, n - 1) lol(j, v[i].size()) { int tmp = dp[i][j] + v[i][j]; if (i < maxi) { dp[i + 1][j] = max(dp[i + 1][j], tmp); dp[i + 1][j + 1] = max(dp[i + 1][j + 1], tmp); } else { if (j + 1 < v[i].size()) dp[i + 1][j] = max(dp[i + 1][j], tmp); if (j > 0) dp[i + 1][j - 1] = max(dp[i + 1][j - 1], tmp); } } cout << dp[n - 1][0] + v[n - 1][0] << endl; return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> #define lol(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 typedef long long ll; using namespace std; vector<int> v[110]; int dp[110][110]; int main() { int n = 0, maxi = 0; string z; while (cin >> z) { z.push_back(','); int cnt = 0; lol(i, z.size()) { if (z[i] == ',') { v[n].push_back(cnt); cnt = 0; } else { cnt *= 10; cnt += z[i] - '0'; } } int tmp = v[n].size(); maxi = max(maxi, tmp); n++; } lol(i, n) lol(j, maxi) dp[i][j] = 0; lol(i, n - 1) lol(j, v[i].size()) { int tmp = dp[i][j] + v[i][j]; if (i < maxi - 1) { dp[i + 1][j] = max(dp[i + 1][j], tmp); dp[i + 1][j + 1] = max(dp[i + 1][j + 1], tmp); } else { if (j + 1 < v[i].size()) dp[i + 1][j] = max(dp[i + 1][j], tmp); if (j > 0) dp[i + 1][j - 1] = max(dp[i + 1][j - 1], tmp); } } cout << dp[n - 1][0] + v[n - 1][0] << endl; return 0; }
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
402
2
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) for (int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; // const int INF = 1e8; using namespace std; vector<string> split(string in, char sp = ',') { vector<string> ret; stringstream ss(in); string s; while (getline(ss, s, sp)) { ret.emplace_back(s); } return ret; } int main() { vector<string> s; string in; while (cin >> in) { s.emplace_back(in); } vector<vector<int>> v(s.size()); rep(i, s.size()) { vector<string> sp = split(s[i]); for (auto j : sp) { v[i].emplace_back(stoi(j)); } } vector<vector<int>> dp(all(v)); rep(i, s.size() / 2) { rep(j, v[i].size()) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + v[i + 1][j]); dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j] + v[i + 1][j + 1]); } } range(i, s.size() / 2, s.size()) { rep(j, v[i].size() - 1) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + v[i + 1][j]); dp[i + 1][j] = max(dp[i + 1][j], dp[i][j + 1] + v[i + 1][j]); } } cout << dp.back().front() << endl; }
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) for (int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; // const int INF = 1e8; using namespace std; vector<string> split(string in, char sp = ',') { vector<string> ret; stringstream ss(in); string s; while (getline(ss, s, sp)) { ret.emplace_back(s); } return ret; } int main() { vector<string> s; string in; while (cin >> in) { s.emplace_back(in); } vector<vector<int>> v(s.size()); rep(i, s.size()) { vector<string> sp = split(s[i]); for (auto j : sp) { v[i].emplace_back(stoi(j)); } } vector<vector<int>> dp(all(v)); rep(i, s.size() / 2) { rep(j, v[i].size()) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + v[i + 1][j]); dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + v[i + 1][j + 1]); } } range(i, s.size() / 2, s.size()) { rep(j, v[i].size() - 1) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + v[i + 1][j]); dp[i + 1][j] = max(dp[i + 1][j], dp[i][j + 1] + v[i + 1][j]); } } cout << dp.back().front() << endl; }
[["+", 3, 4, 0, 69, 341, 342, 0, 16, 17, 72], ["+", 3, 4, 0, 69, 341, 342, 0, 16, 12, 13]]
1
457
2
#include <algorithm> #include <iostream> #include <sstream> #include <string> #include <vector> using namespace std; int main() { vector<string> line(100); int l, k; char cc; stringstream ss; for (l = 0; getline(cin, line[l], '\n'); l++) ; int path[(l + 1) / 2 + 2][l]; for (int i = 0; i < (l + 1) / 2 + 2; i++) path[i][0] = 0; for (int i = 0; i < l; i++) path[0][i] = 0, path[(l + 1) / 2 + 1][i] = 0; ss << line[0]; ss >> path[1][0]; for (int i = 1; i < l; i++) { ss.str(""); ss.clear(stringstream::goodbit); ss << line[i]; for (int j = 0; j < (l + 1) / 2; j++) { k = 0; ss >> k >> cc; if (i <= (l + 1) / 2) path[j + 1][i] = max(path[j][i - 1], path[j + 1][i - 1]) + k; else path[j + 1][i] = max(path[j + 1][i - 1], path[j + 2][i - 1]) + k; } } cout << path[1][l - 1] << endl; return 0; }
#include <algorithm> #include <iostream> #include <sstream> #include <string> #include <vector> using namespace std; int main() { vector<string> line(100); int l, k; char cc; stringstream ss; for (l = 0; getline(cin, line[l], '\n'); l++) ; int path[(l + 1) / 2 + 2][l]; for (int i = 0; i < (l + 1) / 2 + 2; i++) path[i][0] = 0; for (int i = 0; i < l; i++) path[0][i] = 0, path[(l + 1) / 2 + 1][i] = 0; ss << line[0]; ss >> path[1][0]; for (int i = 1; i < l; i++) { ss.str(""); ss.clear(stringstream::goodbit); ss << line[i]; for (int j = 0; j < (l + 1) / 2; j++) { k = 0; ss >> k >> cc; if (i <= l / 2) path[j + 1][i] = max(path[j][i - 1], path[j + 1][i - 1]) + k; else path[j + 1][i] = max(path[j + 1][i - 1], path[j + 2][i - 1]) + k; } } cout << path[1][l - 1] << endl; return 0; }
[["-", 15, 339, 51, 16, 12, 16, 31, 23, 0, 24], ["-", 51, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 51, 16, 12, 16, 31, 23, 0, 16, 12, 13], ["-", 15, 339, 51, 16, 12, 16, 31, 23, 0, 25]]
1
350
4
import static java.lang.Math.*; import static java.util.Arrays.*; import java.util.*; // AOJ 0093 public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { boolean isFirst = true; while (true) { int a, b; a = sc.nextInt(); b = sc.nextInt(); if (a == 0 && b == 0) break; if (isFirst) isFirst = false; else System.out.println(); boolean find = false; for (int y = a; y <= b; y++) { boolean isLeap = false; if (y % 4 == 0) { if (y % 100 != 0) { if (y % 4 == 0) isLeap = true; } else { isLeap = true; } } if (isLeap) { find = true; System.out.println(y); } } if (!find) System.out.println("NA"); } } }
import static java.lang.Math.*; import static java.util.Arrays.*; import java.util.*; // AOJ 0093 public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { boolean isFirst = true; while (true) { int a, b; a = sc.nextInt(); b = sc.nextInt(); if (a == 0 && b == 0) break; if (isFirst) isFirst = false; else System.out.println(); boolean find = false; for (int y = a; y <= b; y++) { boolean isLeap = false; if (y % 4 == 0) { if (y % 100 == 0) { if (y % 400 == 0) isLeap = true; } else { isLeap = true; } } if (isLeap) { find = true; System.out.println(y); } } if (!find) System.out.println("NA"); } } }
[["-", 64, 196, 0, 57, 15, 15, 0, 16, 17, 79], ["+", 64, 196, 0, 57, 15, 15, 0, 16, 17, 60], ["-", 0, 57, 15, 15, 0, 16, 31, 16, 12, 499], ["+", 0, 57, 15, 15, 0, 16, 31, 16, 12, 499]]
3
218
4
import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { Scanner cin = new Scanner(System.in); boolean first = true; while (true) { int a = cin.nextInt(); int b = cin.nextInt(); if (a + b == 0) { break; } if (!first) { System.out.println(); } first = false; boolean isNA = true; for (int i = a + 1; i < b; i++) { if (uruu(i)) { System.out.println(i); isNA = false; } } if (isNA) { System.out.println("NA"); } } } static boolean uruu(int a) { if (a % 400 == 0) { return true; } else if (a % 100 == 0) { return false; } else if (a % 4 == 0) { return true; } else { return false; } } }
import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { Scanner cin = new Scanner(System.in); boolean first = true; while (true) { int a = cin.nextInt(); int b = cin.nextInt(); if (a + b == 0) { break; } if (!first) { System.out.println(); } first = false; boolean isNA = true; for (int i = a; i <= b; i++) { if (uruu(i)) { System.out.println(i); isNA = false; } } if (isNA) { System.out.println("NA"); } } } static boolean uruu(int a) { if (a % 400 == 0) { return true; } else if (a % 100 == 0) { return false; } else if (a % 4 == 0) { return true; } else { return false; } } }
[["-", 0, 7, 502, 503, 49, 200, 51, 16, 17, 72], ["-", 0, 7, 502, 503, 49, 200, 51, 16, 12, 499], ["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 19]]
3
214
4
import java.io.*; import java.util.*; public class Main { public static boolean isLeap(int year) { if (year % 400 == 0) { return true; } else if (year % 100 == 0) { return false; } else return year % 4 == 0; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ArrayList<String> ans = new ArrayList<String>(); while (true) { boolean nan_flag = true; StringTokenizer st = new StringTokenizer(br.readLine(), " "); int a = Integer.parseInt(st.nextToken()); int b = Integer.parseInt(st.nextToken()); if (a == 0 && b == 0) break; for (; a <= b; a++) { if (isLeap(a)) { ans.add(String.valueOf(a)); nan_flag = false; } } if (nan_flag) ans.add("NAN"); ans.add(""); } for (int i = 0; i < ans.size() - 1; i++) { if (ans.get(i).equals("")) { System.out.println(); continue; } System.out.println(ans.get(i)); } } }
import java.io.*; import java.util.*; public class Main { public static boolean isLeap(int year) { if (year % 400 == 0) { return true; } else if (year % 100 == 0) { return false; } else return year % 4 == 0; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ArrayList<String> ans = new ArrayList<String>(); while (true) { boolean nan_flag = true; StringTokenizer st = new StringTokenizer(br.readLine(), " "); int a = Integer.parseInt(st.nextToken()); int b = Integer.parseInt(st.nextToken()); if (a == 0 && b == 0) break; for (; a <= b; a++) { if (isLeap(a)) { ans.add(String.valueOf(a)); nan_flag = false; } } if (nan_flag) ans.add("NA"); ans.add(""); } for (int i = 0; i < ans.size() - 1; i++) { if (ans.get(i).equals("")) { System.out.println(); continue; } System.out.println(ans.get(i)); } } }
[["-", 64, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 64, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
3
296
2
import java.util.*; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); boolean firstFlag = true; while (stdIn.hasNext()) { int a = stdIn.nextInt(); int b = stdIn.nextInt(); if (a == 0 && b == 0) { break; } if (!firstFlag) { System.out.println(""); } boolean existFlag = false; for (int i = a; i <= b; ++i) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { System.out.println(i); existFlag = true; } } if (!existFlag) { System.out.println("NA"); } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); boolean firstFlag = true; while (stdIn.hasNext()) { int a = stdIn.nextInt(); int b = stdIn.nextInt(); if (a == 0 && b == 0) { break; } if (!firstFlag) { System.out.println(""); } boolean existFlag = false; for (int i = a; i <= b; ++i) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { System.out.println(i); existFlag = true; } } if (!existFlag) { System.out.println("NA"); } firstFlag = false; } } }
[["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 147], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
3
173
4
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = ""; ArrayList<String> ds = new ArrayList<String>(); try { while ((s = br.readLine()) != null) { if (s.equals("0 0")) break; ds.add(s); } } catch (IOException e) { e.printStackTrace(); } for (int i = 0; i < ds.size(); i++) { int year1 = Integer.parseInt((ds.get(i).split(" ")[0])); int year2 = Integer.parseInt((ds.get(i).split(" ")[1])); int count = 0; for (int j = year1; j <= year2; j++) { if (isLeep(j)) { System.out.println(j); count++; } } if (count == 0) System.out.println("N/A"); if (i != ds.size() - 1) System.out.println(); } } public static boolean isLeep(int year) { boolean r = false; if (year % 4 == 0) r = true; if (year % 100 == 0) r = false; if (year % 400 == 0) r = true; return r; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = ""; ArrayList<String> ds = new ArrayList<String>(); try { while ((s = br.readLine()) != null) { if (s.equals("0 0")) break; ds.add(s); } } catch (IOException e) { e.printStackTrace(); } for (int i = 0; i < ds.size(); i++) { int year1 = Integer.parseInt((ds.get(i).split(" ")[0])); int year2 = Integer.parseInt((ds.get(i).split(" ")[1])); int count = 0; for (int j = year1; j <= year2; j++) { if (isLeep(j)) { System.out.println(j); count++; } } if (count == 0) System.out.println("NA"); if (i != ds.size() - 1) System.out.println(); } } public static boolean isLeep(int year) { boolean r = false; if (year % 4 == 0) r = true; if (year % 100 == 0) r = false; if (year % 400 == 0) r = true; return r; } }
[["-", 64, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 64, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
3
339
2
#include <stdio.h> int main() { int ya, yb; int i, a = 0, s; while (1) { s = 0; scanf("%d %d", &ya, &yb); if (ya == 0 && yb == 0) break; if (a == 1) printf("\n"); for (i = ya; i < yb; i++) { if (i % 400 == 0 || (!(i % 100 == 0) && i % 4 == 0)) { printf("%d\n", i); s = 1; } } if (s == 0) printf("NA\n"); a = 1; } return 0; }
#include <stdio.h> int main() { int ya, yb; int i, a = 0, s; while (1) { s = 0; scanf("%d %d", &ya, &yb); if (ya == 0 && yb == 0) break; if (a == 1) printf("\n"); for (i = ya; i <= yb; i++) { if (i % 400 == 0 || (!(i % 100 == 0) && i % 4 == 0)) { printf("%d\n", i); s = 1; } } if (s == 0) printf("NA\n"); a = 1; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
0
147
2
#include <stdio.h> int main(void) { int a, b, c, x = 0, i = 0; while (1) { scanf("%d %d", &a, &b); if (a == 0 && b == 0) break; if (x != 0) printf("\n"); else x = 1; for (c = a; c <= b; c++) { if ((c % 4 == 0 && c % 100 != 0) || c % 400) { printf("%d\n", c); i += 1; } } if (i == 0) { printf("NA\n"); i = 0; } } return 0; }
#include <stdio.h> int main(void) { int a, b, c, x = 0, i = 0; while (1) { scanf("%d %d", &a, &b); if (a == 0 && b == 0) break; if (x != 0) printf("\n"); else x = 1; for (c = a; c <= b; c++) { if ((c % 4 == 0 && c % 100 != 0) || c % 400 == 0) { printf("%d\n", c); i += 1; } } if (i == 0) { printf("NA\n"); } i = 0; } return 0; }
[["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
0
147
4
#include <stdio.h> int main() { int a, b; int i; int flg; int first = 1; while (1) { flg = 0; scanf("%d %d", &a, &b); if (a == 0 && b == 0) break; if (first) first = 0; else printf("\n"); for (i = a; i <= b; i++) if ((i % 4 == 0 && i % 100 != 0) || (i % 4 == 0 && i % 400 == 0)) { printf("%d\n", i); flg = 1; } if (flg == 0) printf("NA"); } return 0; }
#include <stdio.h> int main() { int a, b; int i; int flg; int first = 1; while (1) { flg = 0; scanf("%d %d", &a, &b); if (a == 0 && b == 0) break; if (first) first = 0; else printf("\n"); for (i = a; i <= b; i++) if ((i % 4 == 0 && i % 100 != 0) || (i % 4 == 0 && i % 400 == 0)) { printf("%d\n", i); flg = 1; } if (flg == 0) printf("NA\n"); } return 0; }
[["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
150
1
#include <stdio.h> int main(void) { int start, end; int year; int flg_null; int flg_dsp; flg_null = 0; while (1) { scanf("%d%d", &start, &end); if (start == 0 && end == 0) { break; } if (flg_null == 1) { printf("\n"); flg_null = 1; } flg_dsp = 0; for (year = start; year <= end; year++) { if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { printf("%d\n", year); flg_dsp = 1; } } if (flg_dsp == 0) { printf("NA\n"); } } return (0); }
#include <stdio.h> int main(void) { int start, end; int year; int flg_null; int flg_dsp; flg_null = 0; while (1) { scanf("%d%d", &start, &end); if (start == 0 && end == 0) { break; } if (flg_null == 1) { printf("\n"); } flg_null = 1; flg_dsp = 0; for (year = start; year <= end; year++) { if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { printf("%d\n", year); flg_dsp = 1; } } if (flg_dsp == 0) { printf("NA\n"); } } return (0); }
[["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
0
159
2
a, b, i, c, k[3100]; main() { scanf("%d%d", &a, &b); for (;; puts("")) { c = 0; for (i = a; i <= b; i++) if (i % 400 == 0 || (i % 100 != 0 && i % 4 == 0)) k[c++] = i; if (~c) puts("NA"); else { for (i = 0; i < c;) printf("%d\n", k[i++]); } scanf("%d%d", &a, &b); if (~a) exit(0); } }
a, b, i, c, k[3100]; main() { scanf("%d%d", &a, &b); for (;; puts("")) { c = 0; for (i = a; i <= b; i++) if (i % 400 == 0 || (i % 100 != 0 && i % 4 == 0)) k[c++] = i; if (!c) puts("NA"); else { for (i = 0; i < c;) printf("%d\n", k[i++]); } scanf("%d%d", &a, &b); if (!a) exit(0); } }
[["-", 8, 9, 0, 57, 15, 23, 0, 91, 17, 92], ["+", 8, 9, 0, 57, 15, 23, 0, 91, 17, 111]]
0
154
4
x, a, b, i; main(c) { for (; scanf("%d%d", &a, &b), a;) { x &&puts(""); c = 0; for (x = i = a; i <= b; i++) if (i % 400 == 0 || (i % 100 && i % 4 == 0)) c = printf("%d\n", i); c &&puts("NA"); } exit(0); }
x, a, b, i; main(c) { for (; scanf("%d%d", &a, &b), a;) { x &&puts(""); c = 0; for (x = i = a; i <= b; i++) if (i % 400 == 0 || (i % 100 && i % 4 == 0)) c = printf("%d\n", i); c || puts("NA"); } exit(0); }
[["-", 0, 7, 8, 9, 0, 1, 0, 16, 17, 98], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 106]]
0
108
2
#include <stdio.h> int leap(int x) { if (x % 400 == 0) return 1; if (x % 100 == 0) return 0; if (x % 4 == 0) return 1; return 0; } int main() { int a, b, num, i, first = 1; while (1) { scanf("%d%d", &a, &b); if (a == 0 && b == 0) return 0; if (!first) puts(""); first = 0; num = 0; for (i = a; i <= b; i++) { if (leap(i)) { printf("%d\n", i); num++; } } if (num == 0) puts("NA\n"); } }
#include <stdio.h> int leap(int x) { if (x % 400 == 0) return 1; if (x % 100 == 0) return 0; if (x % 4 == 0) return 1; return 0; } int main() { int a, b, num, i, first = 1; while (1) { scanf("%d%d", &a, &b); if (a == 0 && b == 0) return 0; if (!first) puts(""); first = 0; num = 0; for (i = a; i <= b; i++) { if (leap(i)) { printf("%d\n", i); num++; } } if (num == 0) puts("NA"); } }
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
167
1
a, b, f; main(e) { for (; scanf("%d%d", &a, &b) * a;) { if (f) puts(""); e = 1; for (a = -~a / 4 * 4 + 4; a <= b; a += 4) if (!(a % 4) && a % 25 || !(a % 400)) { printf("%d\n", a); e = 0; } if (e) puts("NA"); f = 1; } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
a, b, f; main(e) { for (; scanf("%d%d", &a, &b) * a;) { if (f) puts(""); e = 1; for (a = ~-a / 4 * 4 + 4; a <= b; a += 4) if (!(a % 4) && a % 25 || !(a % 400)) { printf("%d\n", a); e = 0; } if (e) puts("NA"); f = 1; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[["-", 12, 16, 31, 16, 31, 16, 31, 91, 17, 33], ["+", 31, 16, 31, 16, 31, 91, 28, 91, 17, 33]]
0
121
2
e; main(a, b) { for (; scanf("%d%d", &a, &b) * a; e > 1 && puts("NA"), e = 1) for (e &&puts(""); a <= b; a++) a % 4 | a % 25 < 1 && a % 400 || printf("%d\n", e = a); }
e; main(a, b) { for (; scanf("%d%d", &a, &b) * a; e > 1 || puts("NA"), e = 1) for (e &&puts(""); a <= b; a++) a % 4 | a % 25 < 1 && a % 400 || printf("%d\n", e = a); }
[["-", 0, 9, 0, 7, 26, 34, 31, 16, 17, 98], ["+", 0, 9, 0, 7, 26, 34, 31, 16, 17, 106]]
0
87
2
#include <stdio.h> int uruu(int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 1; return 0; } int main(void) { int a, b; int cnt = 0; while (1) { scanf("%d %d", &a, &b); if (a == 0 && b == 0) break; if (cnt) { cnt = 0; } for (; a <= b; a++) { if (uruu(a)) { printf("%d\n", a); cnt = 1; } } if (cnt == 0) { printf("NA\n"); } cnt = 1; } return 0; }
#include <stdio.h> int uruu(int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 1; return 0; } int main(void) { int a, b; int cnt = 0; while (1) { scanf("%d %d", &a, &b); if (a == 0 && b == 0) break; if (cnt) puts(""); cnt = 0; for (; a <= b; a++) { if (uruu(a)) { printf("%d\n", a); cnt = 1; } } if (cnt == 0) { printf("NA\n"); } cnt = 1; } return 0; }
[["-", 0, 52, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["+", 0, 57, 64, 1, 0, 2, 3, 4, 0, 24], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["+", 0, 57, 64, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 52, 8, 9, 0, 57, 64, 1, 0, 35], ["-", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
0
154
8
#include <stdio.h> int main() { int a, b, i, is_first = 0; while (1) { int is_NA = 1; scanf("%d %d", &a, &b); if (a == 0 && b == 0) { break; } if (is_first) { printf("\n"); } for (i = a; i <= b; i++) { if ((i % 4) == 0) { if ((i % 100) == 0) { if ((i % 400) == 0) { printf("%d\n", i); is_NA = 0; } } else { printf("%d\n", i); is_NA = 0; } } } if (is_NA) { printf("NA\n"); } is_first = 0; } return 0; }
#include <stdio.h> int main() { int a, b, i, is_first = 0; while (1) { int is_NA = 1; scanf("%d %d", &a, &b); if (a == 0 && b == 0) { break; } if (is_first) { printf("\n"); } for (i = a; i <= b; i++) { if ((i % 4) == 0) { if ((i % 100) == 0) { if ((i % 400) == 0) { printf("%d\n", i); is_NA = 0; } } else { printf("%d\n", i); is_NA = 0; } } } if (is_NA) { printf("NA\n"); } is_first = 1; } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13]]
0
173
2
#include <stdbool.h> #include <stdio.h> bool is_leap_year(int y); int get_leap_years(int list[], int begin, int end); int main(void) { int leap_years_list[1000]; // A.D. 0 - A.D. 3000 // の間に閏年は高々1000個しかない bool first_set = true; //一つ目のセットの前にだけは改行を入れてはいけないので while (true) { int year_begin, year_end; //読み込み scanf("%d %d", &year_begin, &year_end); //終了判定 if (year_begin == 0 && year_end == 0) { break; } //閏年を計算する int leap_years_count = get_leap_years(leap_years_list, year_begin, year_end); //セットとセットの間には空行を入れる if (first_set) { first_set = false; } else { putchar('\n'); // putcharは一文字だけ出力する関数です } //閏年を出力 if (leap_years_count == 0) { puts("NA"); // putsは与えられた文字列を出力した後改行する関数です } else { for (int i = 0; i < leap_years_count; i++) { printf("%d\n", leap_years_list[i]); } } } } int get_leap_years(int list[], int begin, int end) { int j; for (int year = begin; year <= end; year++) { if (is_leap_year(year)) { list[j] = year; j++; } } return j; } bool is_leap_year(int y) { if (y % 400 == 0) { return true; } else if (y % 100 == 0) { return false; } else { return y % 4 == 0; } }
#include <stdbool.h> #include <stdio.h> bool is_leap_year(int y); int get_leap_years(int list[], int begin, int end); int main(void) { int leap_years_list[1000]; // A.D. 0 - A.D. 3000 // の間に閏年は高々1000個しかない bool first_set = true; //一つ目のセットの前にだけは改行を入れてはいけないので while (true) { int year_begin, year_end; //読み込み scanf("%d %d", &year_begin, &year_end); //終了判定 if (year_begin == 0 && year_end == 0) { break; } //閏年を計算する int leap_years_count = get_leap_years(leap_years_list, year_begin, year_end); //セットとセットの間には空行を入れる if (first_set) { first_set = false; } else { putchar('\n'); // putcharは一文字だけ出力する関数です } //閏年を出力 if (leap_years_count == 0) { puts("NA"); // putsは与えられた文字列を出力した後改行する関数です } else { for (int i = 0; i < leap_years_count; i++) { printf("%d\n", leap_years_list[i]); } } } } int get_leap_years(int list[], int begin, int end) { int j = 0; for (int year = begin; year <= end; year++) { if (is_leap_year(year)) { list[j] = year; j++; } } return j; } bool is_leap_year(int y) { if (y % 400 == 0) { return true; } else if (y % 100 == 0) { return false; } else { return y % 4 == 0; } }
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
273
2
/* 2014.07.04 1230~1243 C language Lecture week ∞ */ #include <stdio.h> int leap_chk(int year); int main(void) { int init; int last; int rcode = 0; int count; while (1) { count = 0; scanf("%d", &init); scanf("%d", &last); if (init == 0 && last == 0) { break; } if (rcode == 0) { rcode = 1; printf("\n"); } for (int ly = init; ly <= last; ly++) { if (leap_chk(ly)) { printf("%d\n", ly); count++; } } if (count == 0) { printf("NA\n"); } } return 0; } int leap_chk(int year) { if (year % 4 == 0) { if (year % 100 == 0) { if (year % 400 == 0) { return 1; } else { return 0; } } else { return 1; } } else { return 0; } }
/* 2014.07.04 1230~1243 C language Lecture week ∞ */ #include <stdio.h> int leap_chk(int year); int main(void) { int init; int last; int rcode = 0; int count; while (1) { count = 0; scanf("%d", &init); scanf("%d", &last); if (init == 0 && last == 0) { break; } if (rcode == 0) { rcode = 1; } else { printf("\n"); } for (int ly = init; ly <= last; ly++) { if (leap_chk(ly)) { printf("%d\n", ly); count++; } } if (count == 0) { printf("NA\n"); } } return 0; } int leap_chk(int year) { if (year % 4 == 0) { if (year % 100 == 0) { if (year % 400 == 0) { return 1; } else { return 0; } } else { return 1; } } else { return 0; } }
[["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 0, 52, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45]]
1
210
3
#include <stdbool.h> #include <stdio.h> bool is_leap_year(int y); int get_leap_years(int *leap_year_array, int start_year, int final_year); int main() { int leap_years_list[1000]; // A.D. 0 - A.D. 3000 // の間に閏年は高々1000個しかない bool first_set = true; //一つ目のセットの前にだけは改行を入れてはいけないので while (true) { int year_begin, year_end; //読み込み scanf("%d %d", &year_begin, &year_end); //終了判定 if (year_begin == 0 && year_end == 0) { break; } //閏年を計算する int leap_years_count = get_leap_years(leap_years_list, year_begin, year_end); //セットとセットの間には空行を入れる if (first_set) { first_set = false; } else { putchar('\n'); // putcharは一文字だけ出力する関数です } //閏年を出力 if (leap_years_count == 0) { puts("NA"); // putsは与えられた文字列を出力した後改行する関数です } else { for (int i = 0; i < leap_years_count; i++) { printf("%d\n", leap_years_list[i]); } } } } bool is_leap_year(int y) { if (y % 400 == 0) { return true; } else if (y % 100 == 0) { return false; } else { return y % 4 == 0; } } int get_leap_years(int *leap_year_array, int start_year, int final_year) { int count = 0; for (int i = start_year; i <= final_year; i++) { if (is_leap_year(i)) { leap_year_array[count] = i; count++; } } return count + 1; }
#include <stdbool.h> #include <stdio.h> bool is_leap_year(int y); int get_leap_years(int *leap_year_array, int start_year, int final_year); int main() { int leap_years_list[1000]; // A.D. 0 - A.D. 3000 // の間に閏年は高々1000個しかない bool first_set = true; //一つ目のセットの前にだけは改行を入れてはいけないので while (true) { int year_begin, year_end; //読み込み scanf("%d %d", &year_begin, &year_end); //終了判定 if (year_begin == 0 && year_end == 0) { break; } //閏年を計算する int leap_years_count = get_leap_years(leap_years_list, year_begin, year_end); //セットとセットの間には空行を入れる if (first_set) { first_set = false; } else { putchar('\n'); // putcharは一文字だけ出力する関数です } //閏年を出力 if (leap_years_count == 0) { puts("NA"); // putsは与えられた文字列を出力した後改行する関数です } else { for (int i = 0; i < leap_years_count; i++) { printf("%d\n", leap_years_list[i]); } } } } bool is_leap_year(int y) { if (y % 400 == 0) { return true; } else if (y % 100 == 0) { return false; } else { return y % 4 == 0; } } int get_leap_years(int *leap_year_array, int start_year, int final_year) { int count = 0; for (int i = start_year; i <= final_year; i++) { if (is_leap_year(i)) { leap_year_array[count] = i; count++; } } return count; }
[["-", 0, 14, 8, 9, 0, 37, 0, 16, 17, 72], ["-", 0, 14, 8, 9, 0, 37, 0, 16, 12, 13]]
1
274
2
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <string> #include <vector> #define pb push_back #define mp make_pair #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, b) loop(i, 0, b) #define all(in) in.begin(), in.end() const double PI = acos(-1); using namespace std; int main() { int a, b; bool h = true; while (cin >> a >> b, a | b) { if (!h) cout << endl; h = false; int co = 0; loop(i, a, b) { if (i % 4 != 0 || (i % 100 == 0 && i % 400 != 0)) ; else { cout << i << endl; co++; } } if (!co) cout << "NA" << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <string> #include <vector> #define pb push_back #define mp make_pair #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, b) loop(i, 0, b) #define all(in) in.begin(), in.end() const double PI = acos(-1); using namespace std; int main() { int a, b; bool h = true; while (cin >> a >> b, a | b) { if (!h) cout << endl; h = false; int co = 0; loop(i, a, b + 1) { if (i % 4 != 0 || (i % 100 == 0 && i % 400 != 0)) ; else { cout << i << endl; co++; } } if (!co) cout << "NA" << endl; } }
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
1
165
3
#include <iostream> using namespace std; int main() { bool f = 0; int a, b; while (cin >> a >> b) { if (a == b && a == 0) break; if (f) cout << endl; for (f = 0; a <= b; a++) { if ((a % 4 == 0) && ((a % 400 != 0) || (a % 400 == 0))) { cout << a << endl; f = 1; } } if (!f) cout << "NA" << endl; f = 1; } return 0; }
#include <iostream> using namespace std; int main() { bool f = 0; int a, b; while (cin >> a >> b) { if (a == b && a == 0) break; if (f) cout << endl; for (f = 0; a <= b; a++) { if ((a % 4 == 0) && ((a % 100 != 0) || (a % 400 == 0))) { cout << a << endl; f = 1; } } if (!f) cout << "NA" << endl; f = 1; } return 0; }
[["-", 0, 16, 31, 23, 0, 16, 31, 16, 12, 13], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 13]]
1
127
2
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <sstream> #include <string> #include <vector> using namespace std; int stoi(string x) { stringstream ss; ss << x; int tmp; ss >> tmp; return tmp; } string itos(int x) { stringstream ss; ss << x; return ss.str(); } int main() { int a, b; bool first = 1; while (cin >> a >> b, a || b) { if (first == 0) cout << endl; first = 0; bool f = 0; for (int i = a; i <= b; i++) { if (i % 4 == 0 && i % 100 != 100 || i % 400 == 0) { cout << i << endl; f = 1; } } if (f == 0) cout << "NA" << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <sstream> #include <string> #include <vector> using namespace std; int stoi(string x) { stringstream ss; ss << x; int tmp; ss >> tmp; return tmp; } string itos(int x) { stringstream ss; ss << x; return ss.str(); } int main() { int a, b; bool first = 1; while (cin >> a >> b, a || b) { if (first == 0) cout << endl; first = 0; bool f = 0; for (int i = a; i <= b; i++) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { cout << i << endl; f = 1; } } if (f == 0) cout << "NA" << endl; } return 0; }
[["-", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13]]
1
183
2
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pair<int, int>> vii; #define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++) #define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--) #define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--) #define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define vrep(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template <class T, class S> inline bool minup(T &m, S x) { return m > (T)x ? (m = (T)x, true) : false; } template <class T, class S> inline bool maxup(T &m, S x) { return m < (T)x ? (m = (T)x, true) : false; } const int INF = 1000000000; const ll MOD = 1000000007LL; const double EPS = 1E-12; int a, b; inline bool isLeap(int y) { if (!(y % 400)) return true; if (!(y % 100)) return false; if (!(y % 4)) return true; return false; } int main() { cin >> a >> b; while (a && b) { int res = 0; bool flag = false; rrep(i, a, b) if (isLeap(i)) { flag = true; cout << i << endl; } if (!flag) cout << "NA" << endl; if ((cin >> a >> b) && a && b) cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pair<int, int>> vii; #define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++) #define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--) #define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--) #define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define vrep(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template <class T, class S> inline bool minup(T &m, S x) { return m > (T)x ? (m = (T)x, true) : false; } template <class T, class S> inline bool maxup(T &m, S x) { return m < (T)x ? (m = (T)x, true) : false; } const int INF = 1000000000; const ll MOD = 1000000007LL; const double EPS = 1E-12; int a, b; inline bool isLeap(int y) { if (!(y % 400)) return true; if (!(y % 100)) return false; if (!(y % 4)) return true; return false; } int main() { cin >> a >> b; while (a && b) { int res = 0; bool flag = false; erep(i, a, b) if (isLeap(i)) { flag = true; cout << i << endl; } if (!flag) cout << "NA" << endl; if ((cin >> a >> b) && a && b) cout << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22]]
1
364
2
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> int main() { int a, b; bool isF = true; while (true) { scanf("%d%d", &a, &b); if (a == 0 && b == 0) { break; } if (isF) { printf("\n"); isF = false; } bool isN = true; for (int i = a; i <= b; ++i) { if ((i % 4 == 0) && ((i % 100 != 0) || (i % 400 == 0))) { printf("%d\n", i); isN = false; } } if (isN) { printf("NA\n"); } } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> int main() { int a, b; bool isF = true; while (true) { scanf("%d%d", &a, &b); if (a == 0 && b == 0) { break; } if (!isF) { printf("\n"); } isF = false; bool isN = true; for (int i = a; i <= b; ++i) { if ((i % 4 == 0) && ((i % 100 != 0) || (i % 400 == 0))) { printf("%d\n", i); isN = false; } } if (isN) { printf("NA\n"); } } return 0; }
[["+", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
1
156
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; int j = 0; while (1) { cin >> a >> b; if (!a && !b) { break; } if (j != 0) cout << endl; int cnt = 0; for (int i = a; i < b; i++) { if (i % 4 == 0) { if (i % 400 == 0) { cout << i << endl; cnt++; } else if (i % 100 != 0) { cnt++; cout << i << endl; } } } if (cnt == 0) cout << "NA" << endl; j = 1; } }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; int j = 0; while (1) { cin >> a >> b; if (!a && !b) { break; } if (j != 0) cout << endl; int cnt = 0; for (int i = a; i <= b; i++) { if (i % 4 == 0) { if (i % 400 == 0) { cout << i << endl; cnt++; } else if (i % 100 != 0) { cnt++; cout << i << endl; } } } if (cnt == 0) cout << "NA" << endl; j = 1; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
144
2
#include <iostream> using namespace std; int main() { int a, b, m = 0; while (cin >> a >> b) { if (!(a || b)) break; if (m > 0) cout << endl; m++; int c = 0; for (int i = a; i <= b; i++) if ((i % 4 == 0) && (i % 100 != 0 || i % 400)) { cout << i << endl; c++; } if (!c) cout << "NA" << endl; } }
#include <iostream> using namespace std; int main() { int a, b, m = 0; while (cin >> a >> b) { if (!(a || b)) break; if (m > 0) cout << endl; m++; int c = 0; for (int i = a; i <= b; i++) if ((i % 4 == 0) && (i % 100 != 0 || i % 400 == 0)) { cout << i << endl; c++; } if (!c) cout << "NA" << endl; } }
[["+", 51, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 51, 16, 12, 23, 0, 16, 12, 16, 12, 13]]
1
120
2
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define pb(n) push_back(n) #define mp(n, m) make_pair(n, m) #define fi first #define se second #define all(r) (r).begin(), (r).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define repc(i, a, b) for (int i = (a); i < (b); i++) typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int IMAX = ((1 << 30) - 1) * 2 + 1; const double EPS = 1e-10; // int mod=1000000007 bool is_Leap(int n) { if (n % 400 == 0) return true; if (n % 100 == 0) return false; if (n % 4 == 0) return true; return false; } int main() { int a, b; bool f = false; while (cin >> a >> b) { if (a == 0 && b == 0) break; if (f) cout << endl; else f = true; vi v; for (int i = a; i < b; i++) { if (is_Leap(i)) v.pb(i); } if (v.empty()) cout << "NA" << endl; else { rep(i, v.size()) { cout << v[i] << endl; } } } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define pb(n) push_back(n) #define mp(n, m) make_pair(n, m) #define fi first #define se second #define all(r) (r).begin(), (r).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define repc(i, a, b) for (int i = (a); i < (b); i++) typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int IMAX = ((1 << 30) - 1) * 2 + 1; const double EPS = 1e-10; // int mod=1000000007 bool is_Leap(int n) { if (n % 400 == 0) return true; if (n % 100 == 0) return false; if (n % 4 == 0) return true; return false; } int main() { int a, b; bool f = false; while (cin >> a >> b) { if (a == 0 && b == 0) break; if (f) cout << endl; else f = true; vi v; for (int i = a; i <= b; i++) { if (is_Leap(i)) v.pb(i); } if (v.empty()) cout << "NA" << endl; else { rep(i, v.size()) { cout << v[i] << endl; } } } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
305
2
#include <iostream> using namespace std; int main(void) { int a, b, count = 0; while (cin >> a >> b, a || b) { if (count) cout << endl; bool NAflag = 0; for (int i = a; i < b; i += 4 - i % 4) { bool flag; if (i % 4 == 0) { if (i % 100 == 0) { if (i % 400 == 0) { flag = 1; } else { flag = 0; } } else { flag = 1; } } else { flag = 0; } if (flag) { NAflag = 1; cout << i << endl; } } if (!NAflag) cout << "NA" << endl; ++count; } return 0; }
#include <iostream> using namespace std; int main(void) { int a, b, count = 0; while (cin >> a >> b, a || b) { if (count) cout << endl; bool NAflag = 0; for (int i = a; i <= b; i += 4 - i % 4) { bool flag; if (i % 4 == 0) { if (i % 100 == 0) { if (i % 400 == 0) { flag = 1; } else { flag = 0; } } else { flag = 1; } } else { flag = 0; } if (flag) { NAflag = 1; cout << i << endl; } } if (!NAflag) cout << "NA" << endl; ++count; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
163
2
#include <iostream> using namespace std; bool isUruu(int y) { if (y % 4 == 0) { if (y % 100 == 0) { if (y % 400 == 0) return true; return false; } return true; } return false; } int main() { int a, b; bool first = true; while (std::cin >> a >> b, a) { if (first) std::cout << std::endl; first = false; bool flag = false; for (int i = a; i <= b; i++) { if (isUruu(i)) { std::cout << i << std::endl; flag = true; } } if (flag == false) std::cout << "NA" << std::endl; } return 0; }
#include <iostream> using namespace std; bool isUruu(int y) { if (y % 4 == 0) { if (y % 100 == 0) { if (y % 400 == 0) return true; return false; } return true; } return false; } int main() { int a, b; bool first = false; while (std::cin >> a >> b, a) { if (first) std::cout << std::endl; first = true; bool flag = false; for (int i = a; i <= b; i++) { if (isUruu(i)) { std::cout << i << std::endl; flag = true; } } if (flag == false) std::cout << "NA" << std::endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 146], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 147], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 147], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 146]]
1
165
26
#include <iostream> using namespace std; int main() { int a, b; int line = 0; while (++line) { cin >> a >> b; if (a == 0 && b == 0) break; int count = 0; if (line > 1) cout << "\n"; for (int i = a; i < b; i++) { if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) { cout << i << "\n"; count++; } } if (count == 0) cout << "NA\n"; } return 0; }
#include <iostream> using namespace std; int main() { int a, b; int line = 0; while (++line) { cin >> a >> b; if (a == 0 && b == 0) break; int count = 0; if (line > 1) cout << "\n"; for (int i = a; i <= b; i++) { if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) { cout << i << "\n"; count++; } } if (count == 0) cout << "NA\n"; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
131
2
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <sstream> #include <stack> #include <vector> using namespace std; #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define PUSH(n, v) \ for (int i = 0; i < (n); i++) { \ int j; \ cin >> j; \ v.push_back(j); \ } #define ALL(v) v.begin(), v.end() #define print(s) cout << (s) << endl bool isleap(int year) { return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); } void solve93(int a, int b) { int cnt = 0; FOR(i, a + 1, b) { if (isleap(i)) cout << i << endl, cnt++; } if (cnt == 0) cout << "NA" << endl; } int main() { int a, b; bool start = true; while (cin >> a >> b, a + b) { if (!start) cout << endl; solve93(a, b); start = false; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <sstream> #include <stack> #include <vector> using namespace std; #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define PUSH(n, v) \ for (int i = 0; i < (n); i++) { \ int j; \ cin >> j; \ v.push_back(j); \ } #define ALL(v) v.begin(), v.end() #define print(s) cout << (s) << endl bool isleap(int year) { return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); } void solve93(int a, int b) { int cnt = 0; FOR(i, a, b + 1) { if (isleap(i)) cout << i << endl, cnt++; } if (cnt == 0) cout << "NA" << endl; } int main() { int a, b; bool start = true; while (cin >> a >> b, a + b) { if (!start) cout << endl; solve93(a, b); start = false; } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
208
4
#include <iostream> using namespace std; int uruu(int i) { if (i % 4 != 0) return 0; else if (i % 400 == 0) return 1; else if (i % 100 == 0) return 0; return 1; } int main() { int a, b, k = 11111; while (1) { cin >> a >> b; if (a == 0) break; if (k != 11111) cout << endl; k = 0; for (int i = a + 1; i < b; i++) { if (uruu(i)) { k++; cout << i << endl; } } if (k == 0) cout << "NA" << endl; } return 0; }
#include <iostream> using namespace std; int uruu(int i) { if (i % 4 != 0) return 0; else if (i % 400 == 0) return 1; else if (i % 100 == 0) return 0; return 1; } int main() { int a, b, k = 11111; while (1) { cin >> a >> b; if (a == 0) break; if (k != 11111) cout << endl; k = 0; for (int i = a; i <= b; i++) { if (uruu(i)) { k++; cout << i << endl; } } if (k == 0) cout << "NA" << endl; } return 0; }
[["-", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["-", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
154
4
#include <iostream> using namespace std; #define p(dis) cout << dis << endl int func(int a, int b) { int f = 1; for (int i = a; i <= b; i++) { if (i % 4 == 0) { if (i % 100 == 0) { if (i % 400 == 0) p(i), f = 0; continue; } p(i), f = 0; } } return f; } int main() { int a, b, f = 0; while (cin >> a >> b, a + b) { if (f) cout << endl; f = 1; if (func(a, b)) cout << "NA" << endl; cout << endl; } return 0; }
#include <iostream> using namespace std; #define p(dis) cout << dis << endl int func(int a, int b) { int f = 1; for (int i = a; i <= b; i++) { if (i % 4 == 0) { if (i % 100 == 0) { if (i % 400 == 0) p(i), f = 0; continue; } p(i), f = 0; } } return f; } int main() { int a, b, f = 0; while (cin >> a >> b, a + b) { if (f) cout << endl; f = 1; if (func(a, b)) cout << "NA" << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
160
4
#include <iostream> using namespace std; int main() { int a, b, x = 0, num = 0; ; while (cin >> a >> b) { if (a == 0 && b == 0) break; if (num == 0) cout << endl; for (int i = a; i <= b; i++) { if (i % 400 == 0) { cout << i << endl; x = 1; } else if (i % 100 == 0) { } else if (i % 4 == 0) { cout << i << endl; x = 1; } } if (x == 0) cout << "NA" << endl; x = 0; num = 1; } return 0; }
#include <iostream> using namespace std; int main() { int a, b, x = 0, num = 0; ; while (cin >> a >> b) { if (a == 0 && b == 0) break; if (num != 0) cout << endl; for (int i = a; i <= b; i++) { if (i % 400 == 0) { cout << i << endl; x = 1; } else if (i % 100 == 0) { } else if (i % 4 == 0) { cout << i << endl; x = 1; } } if (x == 0) cout << "NA" << endl; x = 0; num = 1; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79]]
1
151
2
#include <bits/stdc++.h> #define stirng string #define vvi vector<vector<int>> #define vi vector<int> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; const int inf = 1e9 + 7; /*int main() { string a; cin >> a; string s = ""; for (int i = 0; i < 10; i++) { s += a[i]; } for (int i = 0; i < 44; i++) { int t = s[0 + i] - '0'; int u = s[1 + i] - '0'; s += (t + u) % 10 + '0'; } cout << s[54] << endl; return 0; }*/ int main() { int a, b; int p = 1; while (cin >> a >> b && a != 0 && b != 0) { if (p) { cout << endl; p = 0; } int flag = 1; for (int i = a; i <= b; i++) { if (i % 100 == 0 && i % 400 != 0) { // continue; } else if (i % 4 == 0 && i % 100 != 0) { cout << i << endl; flag = 0; } else if (i % 400 == 0) { cout << i << endl; flag = 0; } else { // continue; } } if (flag) { cout << "NA" << endl; } } return 0; }
#include <bits/stdc++.h> #define stirng string #define vvi vector<vector<int>> #define vi vector<int> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; const int inf = 1e9 + 7; /*int main() { string a; cin >> a; string s = ""; for (int i = 0; i < 10; i++) { s += a[i]; } for (int i = 0; i < 44; i++) { int t = s[0 + i] - '0'; int u = s[1 + i] - '0'; s += (t + u) % 10 + '0'; } cout << s[54] << endl; return 0; }*/ int main() { int a, b; int p = 1; while (cin >> a >> b && a != 0 && b != 0) { if (p == 0) { cout << endl; } p = 0; int flag = 1; for (int i = a; i <= b; i++) { if (i % 100 == 0 && i % 400 != 0) { // continue; } else if (i % 4 == 0 && i % 100 != 0) { cout << i << endl; flag = 0; } else if (i % 400 == 0) { cout << i << endl; flag = 0; } else { // continue; } } if (flag) { cout << "NA" << endl; } } return 0; }
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
1
187
4
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define reep(i, f, n) for (int i = f; i < int(n); ++i) #define rep(i, n) reep(i, 0, n) typedef vector<int> vi; typedef pair<int, int> pii; typedef complex<double> Point; int main() { int a, b; for (int i = 0; scanf("%d%d", &a, &b), a & b; ++i) { bool output = false; if (i) puts(""); reep(j, a, b + 1) { if (j % 4 == 0 && (j % 100 != 0 || j % 400 == 0)) { printf("%d\n", j); output = true; } } if (!output) puts("NA"); } return 0; }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define reep(i, f, n) for (int i = f; i < int(n); ++i) #define rep(i, n) reep(i, 0, n) typedef vector<int> vi; typedef pair<int, int> pii; typedef complex<double> Point; int main() { int a, b; for (int i = 0; scanf("%d%d", &a, &b), a || b; ++i) { bool output = false; if (i) puts(""); reep(j, a, b + 1) { if (j % 4 == 0 && (j % 100 != 0 || j % 400 == 0)) { printf("%d\n", j); output = true; } } if (!output) puts("NA"); } return 0; }
[["-", 8, 9, 0, 7, 15, 34, 12, 16, 17, 67], ["+", 8, 9, 0, 7, 15, 34, 12, 16, 17, 106]]
1
202
2
import sys from collections import defaultdict data_list = [] for line in sys.stdin: data_list.append(list(map(int, line.split()))) def is_half_euler_graph(node_list): isBool = True for node in node_list: for dic_key, dic_value in node.items(): if dic_key != 1 and dic_key != 2: if dic_value % 2 != 0: isBool = False break else : if dic_value % 2 == 0: isBool = False break if isBool : print("OK") else : print("NG") if __name__ == '__main__' : node_data_lists = [] tmp_list = [] count_lists = [] tmp_dic = {} tmp_dic = defaultdict(int) for i in range(0, len(data_list)): if data_list[i][0] == 0 and data_list[i][1] == 0: node_data_lists.append(tmp_list[:]) tmp_list.clear() else : tmp_list.append(data_list[i]) for node_data_list in node_data_lists : tmp_dic.clear() for i in range(0, len(node_data_list)): tmp_dic[node_data_list[i][0]] += 1 tmp_dic[node_data_list[i][1]] += 1 count_lists.append(tmp_dic.copy()) is_half_euler_graph(count_lists)
import sys from collections import defaultdict data_list = [] for line in sys.stdin: data_list.append(list(map(int, line.split()))) def is_half_euler_graph(node_list): for node in node_list: isBool = True for dic_key, dic_value in node.items(): if dic_key != 1 and dic_key != 2: if dic_value % 2 != 0: isBool = False break else : if dic_value % 2 == 0: isBool = False break if isBool : print("OK") else : print("NG") if __name__ == '__main__' : node_data_lists = [] tmp_list = [] count_lists = [] tmp_dic = {} tmp_dic = defaultdict(int) for i in range(0, len(data_list)): if data_list[i][0] == 0 and data_list[i][1] == 0: node_data_lists.append(tmp_list[:]) tmp_list.clear() else : tmp_list.append(data_list[i]) for node_data_list in node_data_lists : tmp_dic.clear() for i in range(0, len(node_data_list)): tmp_dic[node_data_list[i][0]] += 1 tmp_dic[node_data_list[i][1]] += 1 count_lists.append(tmp_dic.copy()) is_half_euler_graph(count_lists)
[["-", 0, 14, 8, 196, 0, 1, 0, 662, 31, 22], ["-", 0, 14, 8, 196, 0, 1, 0, 662, 0, 32], ["-", 0, 14, 8, 196, 0, 1, 0, 662, 12, 146], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 12, 146]]
5
259
6
import sys v=[0]*101 for e in sys.stdin: a,b=map(int,e.split()) if a==0: print(['ng','ok'][1&v[1]and 1&v[2]and sum(x&1 for x in v[3:])==0]) v=[0]*101 v[a]+=1;v[b]+=1
import sys v=[0]*101 for e in sys.stdin: a,b=map(int,e.split()) if a==0: print(['NG','OK'][1&v[1]and 1&v[2]and sum(x&1 for x in v[3:])==0]) v=[0]*101 v[a]+=1;v[b]+=1
[["-", 3, 4, 0, 206, 51, 634, 0, 557, 0, 6], ["+", 3, 4, 0, 206, 51, 634, 0, 557, 0, 6]]
5
99
4
import sys v=[0]*101 for e in sys.stdin: a,b=map(int,e.split()) v[a]+=1;v[b]+=1 if a==0: print(['NG','OK'][v[1]&1*v[2]&1*sum(x&1 for x in v)==2]) v=[0]*101
import sys v=[0]*101 for e in sys.stdin: a,b=map(int,e.split()) v[a]+=1;v[b]+=1 if a==0: print(['NG','OK'][(v[1]&1)*(v[2]&1)*sum(x&1 for x in v)==2]) v=[0]*100
[["+", 206, 666, 0, 657, 31, 657, 31, 23, 0, 24], ["+", 206, 666, 0, 657, 31, 657, 31, 23, 0, 25], ["+", 206, 666, 0, 657, 31, 657, 12, 23, 0, 24], ["+", 206, 666, 0, 657, 31, 657, 12, 23, 0, 25], ["-", 64, 196, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
95
6
while True: try: cross=[0]*101 while True: a,b=list(map(int,input().split())) if (a,b)==(0,0): break cross[a]+=1 cross[b]+=1 if cross[1]%2==cross[2]%2 and len([x for x in cross[3:] if x%2==1])==0: print("OK") else: print("NO") except: break
while True: try: cross=[0]*101 while True: a,b=list(map(int,input().split())) if (a,b)==(0,0): break cross[a]+=1 cross[b]+=1 if cross[1]%2==cross[2]%2==1 and len([x for x in cross[3:] if x%2==1])==0: print("OK") else: print("NG") except: break
[["+", 8, 196, 0, 57, 15, 679, 31, 666, 667, 60], ["+", 8, 196, 0, 57, 15, 679, 31, 666, 0, 612], ["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
115
4
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import (division, absolute_import, print_function, unicode_literals) from sys import stdin from collections import Counter cnt = Counter() for line in stdin: start, end = (int(s) for s in line.split()) if start or end: cnt[start] += 1 cnt[end] += 1 else: semi_eulerian = sum(i % 2 for i in list(cnt.values())) == 2 if semi_eulerian and cnt[1] % 2 and cnt[2] % 2: print('OK') else: print('NO') cnt.clear()
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import (division, absolute_import, print_function, unicode_literals) from sys import stdin from collections import Counter cnt = Counter() for line in stdin: start, end = (int(s) for s in line.split()) if start or end: cnt[start] += 1 cnt[end] += 1 else: semi_eulerian = sum(i % 2 for i in list(cnt.values())) == 2 if semi_eulerian and cnt[1] % 2 and cnt[2] % 2: print('OK') else: print('NG') cnt.clear()
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
126
2
import java.util.*; public class Main { Scanner sc = new Scanner(System.in); void doIt() { while (sc.hasNext()) { Stack<Double> st = new Stack<Double>(); String str[] = sc.nextLine().split(" "); for (int i = 0; i < str.length; i++) { if (str[i].equals("+")) { double x1 = st.pop(); double x2 = st.pop(); st.push(x1 + x2); } else if (str[i].equals("-")) { double x1 = st.pop(); double x2 = st.pop(); st.push(x2 - x1); } else if (str[i].equals("*")) { double x1 = st.pop(); double x2 = st.pop(); st.push(x1 * x2); } else if (str[i].equals("/")) { double x1 = st.pop(); double x2 = st.pop(); st.push(x2 / x1); } else { st.push(Double.parseDouble(str[i])); } } double ans = st.pop(); System.out.printf("%.6f", ans); } } public static void main(String[] args) { // TODO Auto-generated method stub new Main().doIt(); } }
import java.util.*; public class Main { Scanner sc = new Scanner(System.in); void doIt() { while (sc.hasNext()) { Stack<Double> st = new Stack<Double>(); String str[] = sc.nextLine().split(" "); for (int i = 0; i < str.length; i++) { if (str[i].equals("+")) { double x1 = st.pop(); double x2 = st.pop(); st.push(x1 + x2); } else if (str[i].equals("-")) { double x1 = st.pop(); double x2 = st.pop(); st.push(x2 - x1); } else if (str[i].equals("*")) { double x1 = st.pop(); double x2 = st.pop(); st.push(x1 * x2); } else if (str[i].equals("/")) { double x1 = st.pop(); double x2 = st.pop(); st.push(x2 / x1); } else { st.push(Double.parseDouble(str[i])); } } double ans = st.pop(); System.out.println(ans); } } public static void main(String[] args) { // TODO Auto-generated method stub new Main().doIt(); } }
[["-", 0, 52, 8, 196, 0, 1, 0, 492, 141, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 492, 141, 22], ["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 62], ["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["-", 8, 196, 0, 1, 0, 492, 3, 4, 0, 21]]
3
326
6
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Deque; import java.util.LinkedList; import java.util.StringTokenizer; import java.util.regex.Pattern; public class Main { Boolean isNumber(String s) { return Pattern.matches("\\A[0-9]+.?[0-9]*\\z", s); } double solve(String str) { Deque<Double> stack = new LinkedList<Double>(); StringTokenizer st = new StringTokenizer(str); while (st.hasMoreTokens()) { String token = st.nextToken(); if (isNumber(token)) { stack.push(Double.parseDouble(token)); } else { double a = stack.pop(); double b = stack.pop(); double c = 0; switch (token.charAt(0)) { case '+': c = b + a; break; case '-': c = b - a; break; case '*': c = b * a; break; case '/': c = b / a; break; } stack.push(c); } } return stack.pop(); } void io() { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); String str; try { while ((str = input.readLine()) != null) { System.out.println(solve(str)); } } catch (IOException e) { } } public static void main(String[] args) { new Main().io(); } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Deque; import java.util.LinkedList; import java.util.StringTokenizer; import java.util.regex.Pattern; public class Main { boolean isNumber(String s) { return Pattern.matches("\\A-?[0-9]+.?[0-9]*\\z", s); } double solve(String str) { Deque<Double> stack = new LinkedList<Double>(); StringTokenizer st = new StringTokenizer(str); while (st.hasMoreTokens()) { String token = st.nextToken(); if (isNumber(token)) { stack.push(Double.parseDouble(token)); } else { double a = stack.pop(); double b = stack.pop(); double c = 0; switch (token.charAt(0)) { case '+': c = b + a; break; case '-': c = b - a; break; case '*': c = b * a; break; case '/': c = b / a; break; } stack.push(c); } } return stack.pop(); } void io() { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); String str; try { while ((str = input.readLine()) != null) { System.out.println(solve(str)); } } catch (IOException e) { } } public static void main(String[] args) { new Main().io(); } }
[["-", 0, 493, 0, 235, 8, 498, 0, 195, 39, 78], ["+", 0, 493, 0, 235, 8, 498, 0, 195, 39, 523], ["-", 0, 37, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 37, 0, 492, 3, 4, 0, 5, 0, 491]]
3
328
4
#include <ctype.h> #include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> int main() { char num[100] = {'\0'}; char *tp; double stack[220] = {0}; int i, j; while (fgets(num, sizeof(num), stdin) != NULL) { i = 0; tp = strtok(num, " "); stack[i] = atof(tp); i++; while (tp != NULL) { tp = strtok(NULL, " "); if (tp != NULL) { if (tp[0] == '+') { stack[i - 2] += stack[i - 1]; stack[i - 1] = 0; i--; } else if (tp[0] == '-' && (tp[1] < '0' && tp[1] > '9')) { stack[i - 2] -= stack[i - 1]; stack[i - 1] = 0; i--; } else if (tp[0] == '*') { stack[i - 2] *= stack[i - 1]; stack[i - 1] = 0; i--; } else if (tp[0] == '/') { if (stack[i - 1] != 0) { stack[i - 2] /= stack[i - 1]; stack[i - 1] = 0; i--; } else { stack[i - 2] = 0; i--; } } else { stack[i] = atof(tp); i++; } } } printf("%f\n", stack[0]); } return 0; }
#include <ctype.h> #include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> int main() { char num[100] = {'\0'}; char *tp; double stack[220] = {0}; int i, j; while (fgets(num, sizeof(num), stdin) != NULL) { i = 0; tp = strtok(num, " "); stack[i] = atof(tp); i++; while (tp != NULL) { tp = strtok(NULL, " "); if (tp != NULL) { if (tp[0] == '+') { stack[i - 2] += stack[i - 1]; stack[i - 1] = 0; i--; } else if (tp[0] == '-' && (tp[1] < '0' || tp[1] > '9')) { stack[i - 2] -= stack[i - 1]; stack[i - 1] = 0; i--; } else if (tp[0] == '*') { stack[i - 2] *= stack[i - 1]; stack[i - 1] = 0; i--; } else if (tp[0] == '/') { if (stack[i - 1] != 0) { stack[i - 2] /= stack[i - 1]; stack[i - 1] = 0; i--; } else { stack[i - 2] = 0; i--; } } else { stack[i] = atof(tp); i++; } } } printf("%f\n", stack[0]); } return 0; }
[["-", 15, 23, 0, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 17, 106]]
0
363
2
double *q, s[99], *p = s + 2, v; short t[9]; main(c) { for (; ~scanf("%[^ \n]%c", t, &c); c - 10 || printf("%f\n", *--p)) v = *--p, q = p - 1, *q = *t - 43 ? *t - 45 ? *t - 42 ? *t - 47 ? (p++, *p++ = atof(t), *q) : *q / v : *q * v : *q - v : *q + v; }
double *q, s[99], *p = s + 2, v, atof(); short t[9]; main(c) { for (; ~scanf("%[^ \n]%c", t, &c); c - 10 || printf("%f\n", *--p)) v = *--p, q = p - 1, *q = *t - 43 ? *t - 45 ? *t - 42 ? *t - 47 ? (p++, *p++ = atof(t), *q) : *q / v : *q * v : *q - v : *q + v; }
[["+", 36, 36, 36, 36, 0, 30, 0, 43, 0, 21], ["+", 36, 36, 0, 30, 0, 43, 49, 53, 49, 22], ["+", 0, 30, 0, 43, 49, 53, 54, 55, 0, 24], ["+", 0, 30, 0, 43, 49, 53, 54, 55, 0, 25]]
0
136
10
float *q, s[99], *p = s, v, atof(); t; main(c) { for (; t = 0, ~scanf("%s%c", &t, &c); c & 2 && printf("%f \n", *--p)) t < 48 ? v = *--p, q = p - 1, *q = t & 1 ? t & 2 ? t & 4 ? *q / v : *q + v : *q - v : *q * v : (*p++ = atof(&t)); }
double *q, s[99], *p = s, v, atof(); t; main(c) { for (; t = 0, ~scanf("%s%c", &t, &c); c & 2 && printf("%f \n", *--p)) t < 48 ? v = *--p, q = p - 1, *q = t & 1 ? t & 2 ? t & 4 ? *q / v : *q + v : *q - v : *q * v : (*p++ = atof(&t)); }
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40]]
0
128
2
#include <math.h> #include <stdio.h> double stack[200]; int sp; void push(double n) { stack[sp++] = n; } double pop(void) { return (stack[--sp]); } int main(void) { char str[1000]; char *p; double a, b; while (fgets(str, 1000, stdin) != NULL) { p = str; sp = 0; while (*p != '\0' && *p != '\n') { switch (*p) { case '+': a = pop(); b = pop(); push(b + a); p++; break; case '*': a = pop(); b = pop(); push(b * a); p++; break; case '/': a = pop(); b = pop(); push(b / a); p++; break; case ' ': case '\n': p++; break; case '-': if ('0' <= *(p + 1) && *(p + 1) <= '9') { // a = atof(p); // push(a); push(atof(p)); p++; while ('0' <= *p && *p <= '9') { p++; } } else { a = pop(); b = pop(); push(b - a); p++; } break; default: // a = atof(p); // push(a); push(atof(p)); while ('0' <= *p && *p <= '9') { p++; } break; } } // printf("%f\n", stack[0]); printf("%lf\n", pop()); } return (0); }
#include <math.h> #include <stdio.h> double stack[200]; int sp; void push(double n) { stack[sp++] = n; } double pop(void) { return (stack[--sp]); } int main(void) { char str[1000]; char *p; double a, b; while (fgets(str, 1000, stdin) != NULL) { p = str; sp = 0; while (*p != '\0' && *p != '\n') { switch (*p) { case '+': a = pop(); b = pop(); push(b + a); p++; break; case '*': a = pop(); b = pop(); push(b * a); p++; break; case '/': a = pop(); b = pop(); push(b / a); p++; break; case ' ': case '\n': p++; break; case '-': if ('0' <= *(p + 1) && *(p + 1) <= '9') { // a = atof(p); // push(a); push(atoi(p)); p++; while ('0' <= *p && *p <= '9') { p++; } } else { a = pop(); b = pop(); push(b - a); p++; } break; default: // a = atof(p); // push(a); push(atoi(p)); while ('0' <= *p && *p <= '9') { p++; } break; } } // printf("%f\n", stack[0]); printf("%lf\n", pop()); } return (0); }
[["-", 0, 1, 0, 2, 3, 4, 0, 2, 63, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 2, 63, 22]]
0
362
4
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <typeinfo> #include <vector> #define PI 3.14159265359 #define INF 99999999; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(n) rep(i, n) #define EPS 1e-10 typedef long long ll; using namespace std; typedef pair<int, int> P; double distanceAB(double xa, double ya, double xb, double yb); void trace(int A[], int N); /* class Target { public: vector <string> draw(int n) { } }; */ int main() { string inp, w; stack<double> si; int a, b; while (getline(cin, inp)) { stringstream ss(inp); while (ss >> w) { if (w == "+") { a = si.top(); si.pop(); b = si.top(); si.pop(); si.push(a + b); } else if (w == "-") { a = si.top(); si.pop(); b = si.top(); si.pop(); si.push(b - a); } else if (w == "*") { a = si.top(); si.pop(); b = si.top(); si.pop(); si.push(a * b); } else if (w == "/") { a = si.top(); si.pop(); b = si.top(); si.pop(); si.push(b / a); } else { si.push(atoi(w.c_str())); } } cout << fixed << setprecision(6); cout << si.top() << endl; } return 0; } void trace(int A[], int N) { REP(N) { if (i > 0) cout << " "; cout << A[i]; } cout << endl; } double distanceAB(double xa, double ya, double xb, double yb) { return sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya)); }
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <typeinfo> #include <vector> #define PI 3.14159265359 #define INF 99999999; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(n) rep(i, n) #define EPS 1e-10 typedef long long ll; using namespace std; typedef pair<int, int> P; double distanceAB(double xa, double ya, double xb, double yb); void trace(int A[], int N); /* class Target { public: vector <string> draw(int n) { } }; */ int main() { string inp, w; stack<double> si; double a, b; while (getline(cin, inp)) { stringstream ss(inp); while (ss >> w) { if (w == "+") { a = si.top(); si.pop(); b = si.top(); si.pop(); si.push(a + b); } else if (w == "-") { a = si.top(); si.pop(); b = si.top(); si.pop(); si.push(b - a); } else if (w == "*") { a = si.top(); si.pop(); b = si.top(); si.pop(); si.push(a * b); } else if (w == "/") { a = si.top(); si.pop(); b = si.top(); si.pop(); si.push(b / a); } else { si.push(atoi(w.c_str())); } } cout << fixed << setprecision(6); cout << si.top() << endl; } return 0; } void trace(int A[], int N) { REP(N) { if (i > 0) cout << " "; cout << A[i]; } cout << endl; } double distanceAB(double xa, double ya, double xb, double yb) { return sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya)); }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40]]
1
462
2
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; #define rep2(x, from, to) for (int x = (from); x < (to); ++(x)) #define rep(x, to) rep2(x, 0, to) int main() { string str; while (getline(cin, str)) { stack<double> s; stringstream ss; ss << str; while (ss >> str) { if (str[0] >= '0' && str[0] <= '9' || s.size() > 1) { s.push(atoi(str.c_str())); } else { double a = s.top(); s.pop(); double b = s.top(); s.pop(); double c; if (str[0] == '+') c = a + b; else if (str[0] == '-') c = b - a; else if (str[0] == '*') c = a * b; else c = b / a; s.push(c); } } printf("%.6lf\n", s.top()); } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; #define rep2(x, from, to) for (int x = (from); x < (to); ++(x)) #define rep(x, to) rep2(x, 0, to) int main() { string str; while (getline(cin, str)) { stack<double> s; stringstream ss; ss << str; while (ss >> str) { if (str[0] >= '0' && str[0] <= '9' || str.length() > 1) { s.push(atoi(str.c_str())); } else { double a = s.top(); s.pop(); double b = s.top(); s.pop(); double c; if (str[0] == '+') c = a + b; else if (str[0] == '-') c = b - a; else if (str[0] == '*') c = a * b; else c = b / a; s.push(c); } } printf("%.6lf\n", s.top()); } return 0; }
[["-", 51, 16, 12, 16, 31, 2, 63, 118, 28, 22], ["+", 51, 16, 12, 16, 31, 2, 63, 118, 28, 22], ["-", 51, 16, 12, 16, 31, 2, 63, 118, 119, 120], ["+", 51, 16, 12, 16, 31, 2, 63, 118, 119, 120]]
1
241
4
#include <bits/stdc++.h> #define range(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define rep(i, n) range(i, 0, n) using namespace std; int main(void) { while (1) { string s; getline(cin, s); if (cin.eof()) break; stringstream ss(s); vector<double> stk; while (1) { if (ss.eof()) break; string n; ss >> n; if (n.size() == 1 && !isdigit(n[0])) { int b = stk.back(); stk.pop_back(); int a = stk.back(); stk.pop_back(); switch (n[0]) { case '+': stk.push_back(a + b); break; case '-': stk.push_back(a - b); break; case '*': stk.push_back(a * b); break; case '/': stk.push_back(a / b); break; } } else { int num = stoi(n); stk.push_back(1.0 * num); } // for(auto &i:stk) cout << i << endl; } cout.precision(10); cout << fixed << stk[0] << endl; } return 0; }
#include <bits/stdc++.h> #define range(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define rep(i, n) range(i, 0, n) using namespace std; int main(void) { while (1) { string s; getline(cin, s); if (cin.eof()) break; stringstream ss(s); vector<double> stk; while (1) { if (ss.eof()) break; string n; ss >> n; if (n.size() == 1 && !isdigit(n[0])) { double b = stk.back(); stk.pop_back(); double a = stk.back(); stk.pop_back(); switch (n[0]) { case '+': stk.push_back(a + b); break; case '-': stk.push_back(a - b); break; case '*': stk.push_back(a * b); break; case '/': stk.push_back(a / b); break; } } else { int num = stoi(n); stk.push_back(1.0 * num); } // for(auto &i:stk) cout << i << endl; } cout.precision(10); cout << fixed << stk[0] << endl; } return 0; }
[["-", 8, 9, 0, 57, 64, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 57, 64, 9, 0, 43, 39, 40]]
1
258
4
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <stack> using namespace std; int main() { string str; while (getline(cin, str)) { stack<double> S; double now = 0; for (int i = 0; i < str.size(); i++) { if ('0' <= str[i] && str[i] <= '9' && now < 0) { now = now * 10 - (str[i] - '0'); } else if ('0' <= str[i] && str[i] <= '9') { now = now * 10 + (str[i] - '0'); if (i) { if (str[i - 1] == '-') now *= -1; } } else if (str[i] == ' ' && '0' <= str[i - 1] && str[i - 1] <= '9') { S.push(now), now = 0; } else if (str[i] != ' ' && (str[i + 1] == ' ' || i == str.size() - 1)) { int a, b; b = S.top(); S.pop(); a = S.top(); S.pop(); if (str[i] == '+') S.push(a + b); if (str[i] == '-') S.push(a - b); if (str[i] == '*') S.push(a * b); if (str[i] == '/') S.push(a / b); } } if (!S.size()) { cout << str << endl; } else printf("%.12f\n", S.top()); // printf("%.12f\n",S.top()); } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <stack> using namespace std; int main() { string str; while (getline(cin, str)) { stack<double> S; double now = 0; for (int i = 0; i < str.size(); i++) { if ('0' <= str[i] && str[i] <= '9' && now < 0) { now = now * 10 - (str[i] - '0'); } else if ('0' <= str[i] && str[i] <= '9') { now = now * 10 + (str[i] - '0'); if (i) { if (str[i - 1] == '-') now *= -1; } } else if (str[i] == ' ' && '0' <= str[i - 1] && str[i - 1] <= '9') { S.push(now), now = 0; } else if (str[i] != ' ' && (str[i + 1] == ' ' || i == str.size() - 1)) { double a, b; b = S.top(); S.pop(); a = S.top(); S.pop(); if (str[i] == '+') S.push(a + b); if (str[i] == '-') S.push(a - b); if (str[i] == '*') S.push(a * b); if (str[i] == '/') S.push(a / b); } } if (!S.size()) { cout << str << endl; } else printf("%.12f\n", S.top()); // printf("%.12f\n",S.top()); } return 0; }
[["-", 75, 76, 0, 57, 64, 9, 0, 43, 39, 40], ["+", 75, 76, 0, 57, 64, 9, 0, 43, 39, 40]]
1
404
2
#include <iomanip> #include <iostream> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define MAX_DATA_NUM 10000000 int S[MAX_DATA_NUM]; int head; void push(double num) { S[head] = num; head++; if (head == MAX_DATA_NUM) head = 0; } double pop() { head--; double res = S[head]; return res; } // ??\??????1???????????????, ??±??????????????¢?????????????????? // ??? : "10 2 12 - /" -> {"10", "2", "12", "-", "/"} vector<string> read_input() { string line; getline(cin, line); istringstream ss(line); vector<string> parsed_str; while (!ss.eof()) { string tmp; ss >> tmp; parsed_str.push_back(tmp); } return parsed_str; } double solve(vector<string> input_strs) { for (int i = 0; i < input_strs.size(); i++) { if (input_strs[i] == "+") { double a = pop(), b = pop(); push(a + b); } else if (input_strs[i] == "-") { double a = pop(), b = pop(); push(b - a); } else if (input_strs[i] == "*") { double a = pop(), b = pop(); push(a * b); } else if (input_strs[i] == "/") { double a = pop(), b = pop(); push(b / a); } else { push(stod(input_strs[i])); } } double res = pop(); return res; } int main() { while (true) { vector<string> input_strs = read_input(); // ??¨?????????????????±??????????????????????????£??????????????????????????? if (cin.eof()) break; double ans = solve(input_strs); cout << fixed << setprecision(10) << ans << endl; } }
#include <iomanip> #include <iostream> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define MAX_DATA_NUM 10000000 double S[MAX_DATA_NUM]; int head; void push(double num) { S[head] = num; head++; if (head == MAX_DATA_NUM) head = 0; } double pop() { head--; double res = S[head]; return res; } // 入力を1行読み込み, 扱いやすい形式に変換する // 例 : "10 2 12 - /" -> {"10", "2", "12", "-", "/"} vector<string> read_input() { string line; getline(cin, line); istringstream ss(line); vector<string> parsed_str; while (!ss.eof()) { string tmp; ss >> tmp; parsed_str.push_back(tmp); } return parsed_str; } double solve(vector<string> input_strs) { for (int i = 0; i < input_strs.size(); i++) { if (input_strs[i] == "+") { double a = pop(), b = pop(); push(a + b); } else if (input_strs[i] == "-") { double a = pop(), b = pop(); push(b - a); } else if (input_strs[i] == "*") { double a = pop(), b = pop(); push(a * b); } else if (input_strs[i] == "/") { double a = pop(), b = pop(); push(b / a); } else { push(stod(input_strs[i])); } } double res = pop(); return res; } int main() { while (true) { vector<string> input_strs = read_input(); // 全てのテストケースを処理し終わったらループを抜ける if (cin.eof()) break; double ans = solve(input_strs); cout << fixed << setprecision(10) << ans << endl; } }
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40]]
1
381
2
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) for (int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; // const int INF = 1e8; using namespace std; vector<string> split(string in, char sp = ' ') { vector<string> ret; stringstream ss(in); string s; while (getline(ss, s, sp)) { ret.emplace_back(s); } return ret; } int main() { string in; while (getline(cin, in)) { vector<double> st; vector<string> v = split(in); for (auto s : v) { if (s.size() == 1 and not isdigit(s.front())) { int b = st.back(); st.pop_back(); int a = st.back(); st.pop_back(); switch (s[0]) { case '+': st.emplace_back(a + b); break; case '-': st.emplace_back(a - b); break; case '*': st.emplace_back(a * b); break; case '/': st.emplace_back(a / b); break; } } else { st.emplace_back(stod(s)); } } cout << fixed << setprecision(7) << st.front() << endl; } }
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) for (int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; // const int INF = 1e8; using namespace std; vector<string> split(string in, char sp = ' ') { vector<string> ret; stringstream ss(in); string s; while (getline(ss, s, sp)) { ret.emplace_back(s); } return ret; } int main() { string in; while (getline(cin, in)) { vector<double> st; vector<string> v = split(in); for (auto s : v) { if (s.size() == 1 and not isdigit(s.front())) { double b = st.back(); st.pop_back(); double a = st.back(); st.pop_back(); switch (s[0]) { case '+': st.emplace_back(a + b); break; case '-': st.emplace_back(a - b); break; case '*': st.emplace_back(a * b); break; case '/': st.emplace_back(a / b); break; } } else { st.emplace_back(stod(s)); } } cout << fixed << setprecision(7) << st.front() << endl; } }
[["-", 8, 9, 0, 57, 64, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 57, 64, 9, 0, 43, 39, 40]]
1
294
4
#include <iostream> #include <stack> #include <stdio.h> #include <vector> using namespace std; typedef long double ldouble; string in; int main() { while (getline(cin, in)) { stack<ldouble> st; for (int i = 0; i < in.size(); i++) { if (i < in.size() - 1 && in[i] == '-' && in[i + 1] >= '0' && in[i + 1] <= '9') { int s = 0; i++; while (1) { if (in[i] < '0' || in[i] > '9') break; s *= 10; s += in[i] - '0'; i++; } st.push(-1 * s); } if (in[i] >= '0' && in[i] <= '9') { vector<char> V; while (1) { if (in[i] < '0' || in[i] > '9') break; V.push_back(in[i]); i++; } int kake = 1, sum = 0; for (int j = V.size() - 1; j >= 0; j--) { sum += (V[j] - '0') * kake; kake *= 10; } st.push(sum); // st.push(in[i]-'0'); // cout << "push " << sum << endl; } else if (in[i] == '+' || in[i] == '/' || in[i] == '*' || in[i] == '-') { int num[2]; num[0] = st.top(); st.pop(); num[1] = st.top(); st.pop(); if (in[i] == '+') st.push(num[1] + num[0]); if (in[i] == '-') st.push(num[1] - num[0]); if (in[i] == '/') st.push(num[1] / num[0]); if (in[i] == '*') st.push(num[1] * num[0]); } } printf("%.6Lf\n", st.top()); // cout << st.top() << endl; } return 0; }
#include <iostream> #include <stack> #include <stdio.h> #include <vector> using namespace std; typedef long double ldouble; string in; int main() { while (getline(cin, in)) { stack<ldouble> st; for (int i = 0; i < in.size(); i++) { if (i < in.size() - 1 && in[i] == '-' && in[i + 1] >= '0' && in[i + 1] <= '9') { double s = 0; i++; while (1) { if (in[i] < '0' || in[i] > '9') break; s *= 10; s += in[i] - '0'; i++; } st.push(-1 * s); } if (in[i] >= '0' && in[i] <= '9') { vector<char> V; while (1) { if (in[i] < '0' || in[i] > '9') break; V.push_back(in[i]); i++; } double kake = 1, sum = 0; for (int j = V.size() - 1; j >= 0; j--) { sum += (V[j] - '0') * kake; kake *= 10; } st.push(sum); // st.push(in[i]-'0'); // cout << "push " << sum << endl; } else if (in[i] == '+' || in[i] == '/' || in[i] == '*' || in[i] == '-') { double num[2]; num[0] = st.top(); st.pop(); num[1] = st.top(); st.pop(); if (in[i] == '+') st.push(num[1] + num[0]); if (in[i] == '-') st.push(num[1] - num[0]); if (in[i] == '/') st.push(num[1] / num[0]); if (in[i] == '*') st.push(num[1] * num[0]); } } printf("%.6Lf\n", st.top()); // cout << st.top() << endl; } return 0; }
[["-", 8, 9, 0, 57, 64, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 57, 64, 9, 0, 43, 39, 40], ["-", 75, 76, 0, 57, 64, 9, 0, 43, 39, 40], ["+", 75, 76, 0, 57, 64, 9, 0, 43, 39, 40]]
1
502
6
#include <cstdio> #include <cstring> #include <iostream> #include <stack> using namespace std; char in[100]; int main() { while (cin.getline(in, 99) && in[0]) { stack<long double> s; char *c = in; do { if ('0' <= *c && *c <= '9' || *c == '-' && '0' < c[1] && c[1] <= '9') { int a = 0; bool minus = false; if (c[0] == '0') { minus = true; ++c; } while ('0' <= *c && *c <= '9') { a *= 10; a += *c - '0'; ++c; } if (minus) a = -a; s.push((long double)a); } else { long double b = s.top(); s.pop(); long double a = s.top(); s.pop(); switch (*c) { case '+': s.push(a + b); break; case '-': s.push(a - b); break; case '*': s.push(a * b); break; case '/': s.push(a / b); break; } ++c; } ++c; } while (*c); printf("%.6f\n", (double)s.top()); memset(in, 0, sizeof in); } }
#include <cstdio> #include <cstring> #include <iostream> #include <stack> using namespace std; char in[100]; int main() { while (cin.getline(in, 99) && in[0]) { stack<long double> s; char *c = in; do { if ('0' <= *c && *c <= '9' || *c == '-' && '0' < c[1] && c[1] <= '9') { int a = 0; bool minus = false; if (c[0] == '-') { minus = true; ++c; } while ('0' <= *c && *c <= '9') { a *= 10; a += *c - '0'; ++c; } if (minus) a = -a; s.push((long double)a); } else { long double b = s.top(); s.pop(); long double a = s.top(); s.pop(); switch (*c) { case '+': s.push(a + b); break; case '-': s.push(a - b); break; case '*': s.push(a * b); break; case '/': s.push(a / b); break; } ++c; } ++c; } while (*c); printf("%.6f\n", (double)s.top()); memset(in, 0, sizeof in); } }
[["-", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125], ["+", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125]]
1
330
2
#include <algorithm> #include <cctype> #include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string s; while (getline(cin, s)) { stringstream ss(s); stack<double> stk; while (ss >> s) { if (isdigit(s[0])) { stk.push(atof(s.c_str())); } else { double b = stk.top(); stk.pop(); double a = stk.top(); stk.pop(); double res = 0; switch (s[0]) { case '+': res = a + b; break; case '-': res = a - b; break; case '*': res = a * b; break; case '/': res = a / b; break; } stk.push(res); } } printf("%.10f\n", stk.top()); } return 0; }
#include <algorithm> #include <cctype> #include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string s; while (getline(cin, s)) { stringstream ss(s); stack<double> stk; while (ss >> s) { if (isdigit(*s.rbegin())) { stk.push(atof(s.c_str())); } else { double b = stk.top(); stk.pop(); double a = stk.top(); stk.pop(); double res = 0; switch (s[0]) { case '+': res = a + b; break; case '-': res = a - b; break; case '*': res = a * b; break; case '/': res = a / b; break; } stk.push(res); } } printf("%.10f\n", stk.top()); } return 0; }
[["+", 15, 339, 51, 2, 3, 4, 0, 66, 17, 48], ["-", 51, 2, 3, 4, 0, 69, 341, 342, 0, 70], ["-", 51, 2, 3, 4, 0, 69, 341, 342, 0, 13], ["-", 51, 2, 3, 4, 0, 69, 341, 342, 0, 73], ["+", 3, 4, 0, 66, 28, 2, 63, 118, 17, 131], ["+", 3, 4, 0, 66, 28, 2, 63, 118, 119, 120], ["+", 3, 4, 0, 66, 28, 2, 3, 4, 0, 24], ["+", 3, 4, 0, 66, 28, 2, 3, 4, 0, 25]]
1
209
8