Google Code Jam 2008 Practice one
http://code.google.com/codejam/contest/dashboard?c=agdjb2RlamFtcg4LEghjb250ZXN0cxh5DA
Arbitrary size numberal system conversion
1. numInputSystem[inputSystem[i]], inputSystem[i] is a char, actually converts to ASC2 in this array.
These 94 signals or numbers are consistent ASC2 codes.
2. Converts to decimal at first.
Java code:
public class CodeJam1 {
public static void convertSystem(char[] alienNum, char[] inputSystem, char[] outputSystem) {
int inputSize = inputSystem.length;
int outputSize = outputSystem.length;
int[] numInputSystem = new int[300];
for(int i = 0;i < inputSize;i ++) {
numInputSystem[inputSystem[i]] = i;
}
int x = 0;
for(int i = 0;i < alienNum.length;i ++) {
x = (x * inputSize) + numInputSystem[alienNum[i]];
}
//Decimal Number
System.out.println(x);
StringBuilder output = new StringBuilder();
while(x != 0) {
StringBuilder temp = new StringBuilder();
output = temp.append(outputSystem[x % outputSize]).append(output);
x /= outputSize;
}
System.out.println("Case #1: " + output.toString());
}
public static void main(String[] args) {
char[] alienNum = "CODE".toCharArray();
char[] inputSystem = "O!CDE?".toCharArray();
char[] outputSystem = "A?JM!.".toCharArray();
// char[] alienNum = "2".toCharArray();
// char[] inputSystem = "0123456789".toCharArray();
// char[] outputSystem = "01".toCharArray();
// char[] alienNum = "10".toCharArray();
// char[] inputSystem = "01".toCharArray();
// char[] outputSystem = "0123456789".toCharArray();
CodeJam1.convertSystem(alienNum, inputSystem, outputSystem);
}
}
C code
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <cctype>
#define int64 long long
#define ii pair<int,int>
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v.size()))
using namespace std;
template<class T> T abs(T x){return x>0 ? x:(-x);}
template<class T> T sqr(T x){return x*x;}
int num1[300],num2[300];
int c1,c2;
int main()
{
int n;
cin >> n;
for(int ic=0;ic<n;ic++){
memset(num1,-1,sizeof(num1));
string s,s1,s2;
cin >> s >> s1 >> s2;
for(int i=0;i<sz(s1);i++)
num1[s1[i]]=i;
for(int i=0;i<sz(s2);i++)
num2[s2[i]]=i;
c1=sz(s1);
c2=sz(s2);
int64 x=0;
for(int i=0;i<sz(s);i++){
if(num1[s[i]]==-1) while(1);
x=(x*(int64)c1)+(int64)(num1[s[i]]);
}
string ss;
if(!x) ss+=s2[0];
while(x){
ss=s2[x%c2]+ss;
x/=c2;
}
cout << "Case #" << ic+1 << ": " << ss << "\n";
}
return 0;
}
分享到:
相关推荐
React动画的数字 在react.js中显示数字变化动画的库 测试 道具 名称 类型 默认 描述 animateToNumber 数字 没有任何 动画编号 animationType “平静”或“随机”` “随机的” ...import React from 'reac
print("The alien's color is " + alien['color']) # 添加新的键值对 alien['x_position'] = 0 # 遍历所有键值对 fav_numbers = {'eric': 17, 'ever': 4} for name, number in fav_numbers.items(): print(name +...
aliens = [alien_0, alien_1, alien_2] for alien in aliens: print(alien) ``` - **字典中存储列表**: ```python favorite_language = { 'jen': ['python', 'c'], 'mx': ['java', 'python'] } for name...
例如,使用for循环遍历fav_numbers字典中的所有项。 遍历字典的键和值(Looping through all keys and values in a dictionary): 遍历字典的所有键和值。例如,使用.keys()和.values()方法。 以上知识点涵盖了...
print("The alien's color is " + alien['color']) ``` ##### 向字典添加新的键值对 ```python alien['x_position'] = 0 ``` ##### 遍历字典中的所有键值对 ```python fav_numbers = {'eric': 17, 'ever': 4} ...
1383 Binary Numbers 简单题 1403 Safecracker 简单题 1408 The Fun Number System 简单题 1486 Color the Tree 简单题 1487 Playing Cards 简单题 1489 2^x mod n = 1 简单题,应该有好算法,不过枚举就...
1383 Binary Numbers 简单题 1403 Safecracker 简单题 1408 The Fun Number System 简单题 1486 Color the Tree 简单题 1487 Playing Cards 简单题 1489 2^x mod n = 1 简单题,应该有好算法,不过枚举就...
:input_numbers: 版本凹凸 如果package.json中的版本与npm上的最新发布版本相同或更低,则将版本增加到下一个预发行版本。 :hot_pepper: 请注意,预发行版本的顺序很奇怪:0.0.1、0.0.2-1、0.0.2-2、0.0.2、0.0.3-1...
- “At present, our spacecraft are too slow to carry large numbers of passengers to Mars—it would take months.” 描述了当前技术限制,飞往火星需要较长时间。 - “With the development of technology, ...
18. **1085 - Alien Security**:外星人安全问题。 19. **1097 - Code the Tree**:树编码问题。 20. **1060 - Sorting It All Out**:排序问题。 21. **1105 - Fat Mouse's Tour**:老鼠旅行问题。 22. **1119 - ...