macの「delete」キーはwindowsと異なる。
macの「delete」はwindowsでの「Backspace」キーに相当する。
windowsでいう「delete」キーを使用するには「fn」+「delete」とすればよい。
Amazon
2013年10月1日火曜日
2013年3月13日水曜日
Sublime Text2 - Java - Decode error - output not utf-8
Sublime Text2でjavaプログラムを
Tool -> Build (Ctrl + B)しようとすると
Decode error - output not utf-8
という結果が。。。
ということで、PreferencesのBrowse Packages...から
Javaフォルダを見つけ。。。
フォルダ内にある、"JavaC.sublime-build"ファイルに
"encoding":"cp932"の一文を追加
","の区切りを忘れずに。。。
結果、エラーが解消(・∀・)
今回、このエラーを解消する過程で
ConvertToUTF8なるパッケージを見つけ、せっかくなんでこれも追加(*^_^*)
Tool -> Build (Ctrl + B)しようとすると
Decode error - output not utf-8
という結果が。。。
ということで、PreferencesのBrowse Packages...から
"encoding":"cp932"の一文を追加
","の区切りを忘れずに。。。
結果、エラーが解消(・∀・)
今回、このエラーを解消する過程で
ConvertToUTF8なるパッケージを見つけ、せっかくなんでこれも追加(*^_^*)
2013年3月5日火曜日
2012年10月4日木曜日
AOJ Volume0 0033: Ball
Bの筒に入れて問題無いか確認→問題なければBを更新
Bの筒に入れられない場合はCの筒で同様に
どちらにも入れられない→Noを出力
すべて入れられたら→Yes
/****************************************
* 2012/10/04 *
* AOJ Volume0 0033 Ball *
* crane *
*****************************************/
#include<iostream>
#include<queue>
using namespace std;
int main(){
int n = 0;
cin >> n;
queue<int> data;
while(n--){
data.empty();
int num = 10, input = 0;
while(num--){
cin >> input;
data.push(input);
}
int b = 0, c = 0, count = 10;
bool frag = true;
while(count--){
int f = data.front();
if(f > b) b = f;
else if(f > c) c = f;
else frag = false;
data.pop();
}
if(frag) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
Bの筒に入れられない場合はCの筒で同様に
どちらにも入れられない→Noを出力
すべて入れられたら→Yes
/****************************************
* 2012/10/04 *
* AOJ Volume0 0033 Ball *
* crane *
*****************************************/
#include<iostream>
#include<queue>
using namespace std;
int main(){
int n = 0;
cin >> n;
queue<int> data;
while(n--){
data.empty();
int num = 10, input = 0;
while(num--){
cin >> input;
data.push(input);
}
int b = 0, c = 0, count = 10;
bool frag = true;
while(count--){
int f = data.front();
if(f > b) b = f;
else if(f > c) c = f;
else frag = false;
data.pop();
}
if(frag) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
2012年7月16日月曜日
AOJ Volume11 1179: Millennium
/*******************************
* 2012/07/06 *
* AOJ Volume11 1179 *
* Millennium *
* crane *
********************************/
#include <iostream>
using namespace std;
#define MAX_N 1001
int field[MAX_N][11];
int main() {
for(int i=1; i<=999; i++){
for(int j=1; j<=10; j++){
field[i][j] = 0;
}
}
int frag = 0;
for(int i=1; i<=999; i++){
frag = 0;
if(i % 3 == 0)
frag = 1;
for(int j=1; j<=10; j++){
if(frag == 1)
field[i][j] = 20;
else{
if(j%2 == 0){
field[i][j] = 19;
}else{
field[i][j] = 20;
}
}
}
}
/* input */
int n;
cin >> n;
for(int i=0; i<n; i++){
int y=0, m=0, d=0;
cin >> y >> m >> d;
long long sum=0;
int frag2=0;
int a = m;
for(int j=y; j<1000; j++){
if(frag2 == 1) a=1;
for(int k=a; k<=10; k++){
if(frag2 == 0){
sum += field[j][k] - d;
frag2 = 1;
}else{
sum += field[j][k];
}
}
}
cout << sum+1 << endl;
}
return 0;
}
2012年7月15日日曜日
AOJ Volume1 0158: Collatz's Problem
- n が偶数の時は 2 で割る。
- n が奇数の時は 3 倍し、1 を足す。
- 整数 n は1以上でかつ上記の計算を繰り返す途中の値が1000000以下となる程度の整数とあったのでint からlongに変更。
/******************************
* 2012/07/15 *
* AOJ_Volume1_0158 *
* Collatz's Problem *
* crane *
*******************************/
#include<iostream>
using namespace std;
int main(){
long long int n;
while(cin >> n, n){
int count = 0;
while(1){
if(n == 1) break;
if(n % 2 == 0) n /= 2;
else n = (n*3) + 1;
count++;
}
cout << count << endl;
}
return 0;
}
AOJ Volume5 0538: IOIOI
単純に回したのでは時間切れとなったので
考え方を変更した。
P1ならIOI P2ならIOIOI
となるはずなので、IOIの連続出現回数をカウントしていく。
P1なら1回、P2なら2回連続で出現したらresをインクリメント
/*****************************
* 2012/07/15 *
* AOJ_Volume5_0538 *
* IOIOI *
* crane *
******************************/
#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
while(cin >> n, n){
int m;
cin >> m;
string s;
cin >> s;
int count=0, res= 0;
for(int i=0; i<m;){
if(s.substr(i, 3) == "IOI"){
count++;
if(n <= count) res++;
}else {
count = 0;
}
if(count == 0) i++;
else i+=2;
}
cout << res << endl;
}
return 0;
}
考え方を変更した。
P1ならIOI P2ならIOIOI
となるはずなので、IOIの連続出現回数をカウントしていく。
P1なら1回、P2なら2回連続で出現したらresをインクリメント
/*****************************
* 2012/07/15 *
* AOJ_Volume5_0538 *
* IOIOI *
* crane *
******************************/
#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
while(cin >> n, n){
int m;
cin >> m;
string s;
cin >> s;
int count=0, res= 0;
for(int i=0; i<m;){
if(s.substr(i, 3) == "IOI"){
count++;
if(n <= count) res++;
}else {
count = 0;
}
if(count == 0) i++;
else i+=2;
}
cout << res << endl;
}
return 0;
}
ラベル:
AOJ,
AOJ_Volume5,
文字列
2012年7月14日土曜日
AOJ Volume11 1129: Hanafuda Shuffle (POJ1978)
問題文通りにそのまま書いてみた。
/********************************
* 2012/0623 *
* AOJ VOlume11 1129 *
* POJ1978 *
* 花札シャッフル *
* crane *
********************************/
#include<iostream>
#define MAX_N 50
int card[MAX_N]; //カード内容
int t_card[MAX_N]; //シャッフル用カードtmp
int main(){
int n = 0; //札の枚数
int r = 0; //カット回数
int p = 0; //p枚目から
int c = 0; //c枚取り出す
while(std::cin >> n >> r, n, r){
//配列の初期化
for(int i=0; i<n; i++) card[i] = i + 1;
//shuffle
for(int i=0; i<r; i++){ //カット回数r分
std::cin >> p >> c;
for(int j=0; j<c; j++)
t_card[c-1-j] = card[n-p-j];
for(int j=n-p+1; j<n; j++)
card[j-c] = card[j];
for(int j=0; j<c; j++)
card[n-c+j] = t_card[j];
}
std::cout << card[n-1] << std::endl;
}
return 0;
}
/********************************
* 2012/0623 *
* AOJ VOlume11 1129 *
* POJ1978 *
* 花札シャッフル *
* crane *
********************************/
#include<iostream>
#define MAX_N 50
int card[MAX_N]; //カード内容
int t_card[MAX_N]; //シャッフル用カードtmp
int main(){
int n = 0; //札の枚数
int r = 0; //カット回数
int p = 0; //p枚目から
int c = 0; //c枚取り出す
while(std::cin >> n >> r, n, r){
//配列の初期化
for(int i=0; i<n; i++) card[i] = i + 1;
//shuffle
for(int i=0; i<r; i++){ //カット回数r分
std::cin >> p >> c;
for(int j=0; j<c; j++)
t_card[c-1-j] = card[n-p-j];
for(int j=n-p+1; j<n; j++)
card[j-c] = card[j];
for(int j=0; j<c; j++)
card[n-c+j] = t_card[j];
}
std::cout << card[n-1] << std::endl;
}
return 0;
}
AOJ Volume20 2013: Osaki
hh:mm:ss で与えられるため秒に統一する。
hh ->*60*60
mm->*60
ss
その時間に出発した電車、到着した電車の数をカウントする。
その時間にどれだけの電車が走っているかをカウントし、その最大値が答えになる。
/*********************************
* 2012/0714 *
* AOJ_Volume20_2013 *
* Osaki *
* crane *
**********************************/
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX_N 24*60*60
int field[MAX_N];
int main(){
int n;
while(cin >> n, n){
for(int i=0; i<MAX_N; i++)
field[i] = 0;
int h1,m1,s1,h2,m2,s2;
for(int i=0; i<n; i++){
scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
int t1 = (h1 * 3600) + (m1 * 60) + s1;//秒に統一
int t2 = (h2 * 3600) + (m2 * 60) + s2;
field[t1]++; //その時間に出発した電車をカウント
field[t2]--; //その時間に到着した電車をカウント
}
int m_count=0, count=0;
for(int i=0; i<MAX_N; i++){//その時間に走っている車両数の最大値が答えになる。
count += field[i];
m_count = max(m_count, count);
}
cout << m_count << endl;
}
return 0;
}
hh ->*60*60
mm->*60
ss
その時間に出発した電車、到着した電車の数をカウントする。
その時間にどれだけの電車が走っているかをカウントし、その最大値が答えになる。
/*********************************
* 2012/0714 *
* AOJ_Volume20_2013 *
* Osaki *
* crane *
**********************************/
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX_N 24*60*60
int field[MAX_N];
int main(){
int n;
while(cin >> n, n){
for(int i=0; i<MAX_N; i++)
field[i] = 0;
int h1,m1,s1,h2,m2,s2;
for(int i=0; i<n; i++){
scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
int t1 = (h1 * 3600) + (m1 * 60) + s1;//秒に統一
int t2 = (h2 * 3600) + (m2 * 60) + s2;
field[t1]++; //その時間に出発した電車をカウント
field[t2]--; //その時間に到着した電車をカウント
}
int m_count=0, count=0;
for(int i=0; i<MAX_N; i++){//その時間に走っている車両数の最大値が答えになる。
count += field[i];
m_count = max(m_count, count);
}
cout << m_count << endl;
}
return 0;
}
AOJ Volume2 0206: Next Trip
/****************************
* 2012/07/14 *
* AOJ_Volume2_0206 *
* Next Trip *
* crane *
*****************************/
#include<iostream>
using namespace std;
int main(){
int pri;
while(cin >> pri, pri){
int res;
bool frag = false;
for(int i=1; i<=12; i++){
int m,n;
cin >> m >> n;
pri -= m-n;
if(pri <= 0 && frag != true){
frag = true;
res = i;
}
}
if(frag) cout << res << endl;
else cout << "NA" << endl;
}
return 0;
}
* 2012/07/14 *
* AOJ_Volume2_0206 *
* Next Trip *
* crane *
*****************************/
#include<iostream>
using namespace std;
int main(){
int pri;
while(cin >> pri, pri){
int res;
bool frag = false;
for(int i=1; i<=12; i++){
int m,n;
cin >> m >> n;
pri -= m-n;
if(pri <= 0 && frag != true){
frag = true;
res = i;
}
}
if(frag) cout << res << endl;
else cout << "NA" << endl;
}
return 0;
}
AOJ Volume1 0149: Eye Test
判定関数においてA~Dそれぞれの範囲をわかりやすくするため
すべての下限上限を書いた。
A~Dの配列0~4だけどmap<char, int>なんかで扱っても良かったかも。
/****************************
* 2012/07/14 *
* AOJ_Volume1_0149 *
* Eye Test *
* crane *
*****************************/
//--------------------------------------//
// 判定 視力 //
// A 1.1以上 //
// B 0.6以上1.1未満 //
// C 0.2以上0.6未満 //
// D 0.2未満 //
//--------------------------------------//
#include<iostream>
#include<map>
using namespace std;
int solve(double x);
int main(){
int ldata[4] = {0, 0, 0, 0};
int rdata[4] = {0, 0, 0, 0};
double left, right;
while(cin >> left >> right){
int le = solve(left);
int ri = solve(right);
ldata[le]++;
rdata[ri]++;
}
for(int i=0; i<4; i++)
cout << ldata[i] << " " << rdata[i] << endl;
return 0;
}
int solve(double x){
if(1.1 <= x) return 0;
else if(0.6<=x && x<1.1) return 1;
else if(0.2<=x && x<0.6) return 2;
else if(x<0.2) return 3;
}
すべての下限上限を書いた。
A~Dの配列0~4だけどmap<char, int>なんかで扱っても良かったかも。
/****************************
* 2012/07/14 *
* AOJ_Volume1_0149 *
* Eye Test *
* crane *
*****************************/
//--------------------------------------//
// 判定 視力 //
// A 1.1以上 //
// B 0.6以上1.1未満 //
// C 0.2以上0.6未満 //
// D 0.2未満 //
//--------------------------------------//
#include<iostream>
#include<map>
using namespace std;
int solve(double x);
int main(){
int ldata[4] = {0, 0, 0, 0};
int rdata[4] = {0, 0, 0, 0};
double left, right;
while(cin >> left >> right){
int le = solve(left);
int ri = solve(right);
ldata[le]++;
rdata[ri]++;
}
for(int i=0; i<4; i++)
cout << ldata[i] << " " << rdata[i] << endl;
return 0;
}
int solve(double x){
if(1.1 <= x) return 0;
else if(0.6<=x && x<1.1) return 1;
else if(0.2<=x && x<0.6) return 2;
else if(x<0.2) return 3;
}
2012年7月13日金曜日
AOJ Volume1 0134: Exit Survey
int sumでは足りないのでlong longで対応
/*****************************
* 2012/07/13 *
* AOJ_Volume1_0134 *
* Exit_Survey *
* crane *
******************************/
#include<iostream>
using namespace std;
int main(){
int n, input;
cin >> n;
long long int sum = 0;
for(int i=0; i<n; i++){
cin >> input;
sum += input;
}
cout << sum/n << endl;
return 0;
}
/*****************************
* 2012/07/13 *
* AOJ_Volume1_0134 *
* Exit_Survey *
* crane *
******************************/
#include<iostream>
using namespace std;
int main(){
int n, input;
cin >> n;
long long int sum = 0;
for(int i=0; i<n; i++){
cin >> input;
sum += input;
}
cout << sum/n << endl;
return 0;
}
AOJ Volume1 0127: Pocket Pager Input
/*********************************
* 2012/07/13 *
* AOJ_Volume1_0127 *
* Pocket_Pager_Input *
* crane *
**********************************/
#include<iostream>
#include<string>
using namespace std;
char data[7][6] ={
{},
{' ','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','.','?','!',' '}
};
int main(){
string input;
while(1){
getline(cin, input);
if(input.empty())break;
bool frag = true;
string output = "";
if(input.length() % 2 != 0)
frag = false;
for(int i=0; i<input.length() && frag==true; i+=2){
int in1 = (int) input.at(i) - '0';
int in2 = (int) input.at(i+1) - '0';
if(0<in1 && in1 < 7 && 0 < in2 && in2 < 6)
output += data[in1][in2];
else
frag = false;
}
if(frag) cout << output << endl;
else cout << "NA" << endl;
}
return 0;
}
* 2012/07/13 *
* AOJ_Volume1_0127 *
* Pocket_Pager_Input *
* crane *
**********************************/
#include<iostream>
#include<string>
using namespace std;
char data[7][6] ={
{},
{' ','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','.','?','!',' '}
};
int main(){
string input;
while(1){
getline(cin, input);
if(input.empty())break;
bool frag = true;
string output = "";
if(input.length() % 2 != 0)
frag = false;
for(int i=0; i<input.length() && frag==true; i+=2){
int in1 = (int) input.at(i) - '0';
int in2 = (int) input.at(i+1) - '0';
if(0<in1 && in1 < 7 && 0 < in2 && in2 < 6)
output += data[in1][in2];
else
frag = false;
}
if(frag) cout << output << endl;
else cout << "NA" << endl;
}
return 0;
}
2012年7月11日水曜日
AOJ Volume0 013: Switching Railroad Cars
stackを用いる。
/*****************************
* 2012/07/11 *
* AOJ_Volume0_0013 *
* Switching_Railroad_Cars *
* crane *
******************************/
#include<iostream>
#include<stack>
using namespace std;
int main(){
stack<int> data;
int n;
while(cin >> n){
if(n == 0){
cout << data.top() << endl;
data.pop();
}else data.push(n);
}
return 0;
}
/*****************************
* 2012/07/11 *
* AOJ_Volume0_0013 *
* Switching_Railroad_Cars *
* crane *
******************************/
#include<iostream>
#include<stack>
using namespace std;
int main(){
stack<int> data;
int n;
while(cin >> n){
if(n == 0){
cout << data.top() << endl;
data.pop();
}else data.push(n);
}
return 0;
}
2012年7月10日火曜日
AOJ Volume1 0139: Snakes
A種は,">'"の後に"="が1個以上並んだ後、"#"が来て、さらに前と同じ個数の"="が来た後、"~"(半角チルダ)で終わる。
B種は,">^"の後に "Q="が1個以上並んだ後、"~~"で終わる。
B種は,">^"の後に "Q="が1個以上並んだ後、"~~"で終わる。
A種の例: >'====#====~ >'==#==~
B種の例: >^Q=Q=Q=Q=~~ >^Q=Q=~~
/************************
* 2012/07/10 *
* AOJ_Volume1_0139 *
* Snakes *
* crane *
*************************/
#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
cin >> n;
while(n--){
string input;
cin >> input;
if(input.length() <5){
cout << "NA" << endl;
}else{
string s = input.substr(0,2); //どの蛇か
char e = input.at(input.length()-1); //A B尾判定
char e2 = input.at(input.length()-2);//B 尾判定
if(input.length() % 2 != 0){//lengthが偶数出ないものはAでもBでもない
cout << "NA" << endl;
}else if(s == ">'" && e == '~'){ //SnakeA
bool frag_A = true;
for(int i=2; i<input.length()/2; i++){
char c1 = input.at(i); //前から
char c2 = input.at(input.length()-i);//後ろから
if(c1 != '=' || c2 != '='){
cout << "NA" << endl;
frag_A = false;
break;
}
}
char a = input.at(input.length()/2 );
if(a == '#' && frag_A) cout << "A" << endl;
}else if(s == ">^" && e == '~' && e2 == '~'){ //SnakeB
bool frag_B = true;
for(int i=2; i<input.length()-2; i+=2){
string s1 = input.substr(i, 2);
if(s1 != "Q="){
cout << "NA" << endl;
frag_B = false;
break;
}
}
if(frag_B)cout << "B" << endl;
}else cout << "NA"<< endl;
}
}
return 0;
}
2012年7月9日月曜日
APJ Volume0 0044: Prime Number Ⅱ
/******************************
* 2012/07/09 *
* AOJ_Volume0_0044 *
* Prime_NumberⅡ *
* crane *
*******************************/
#include<iostream>
#include<cmath>
using namespace std;
#define MAX_N 50023
bool field[MAX_N];
int prime[MAX_N];
int main(){
for(int i=2; i<MAX_N; i++){
field[i] = true;
prime[i] = 0;
}
int count = 0;
field[0] = false;
field[1] = false;
for(int i=2; i<MAX_N; i++){
if(field[i]){
prime[count] = i;
count++;
for(int j=i*2; j<MAX_N; j+=i){
field[j] = false;
}
}
}
int n;
while(cin >> n){
int a=0;
for(int i=0; i<MAX_N; i++){
if(prime[i] < n) a=prime[i];
if(n < prime[i]){
cout << a << " " << prime[i] << endl;
break;
}
}
}
return 0;
}
* 2012/07/09 *
* AOJ_Volume0_0044 *
* Prime_NumberⅡ *
* crane *
*******************************/
#include<iostream>
#include<cmath>
using namespace std;
#define MAX_N 50023
bool field[MAX_N];
int prime[MAX_N];
int main(){
for(int i=2; i<MAX_N; i++){
field[i] = true;
prime[i] = 0;
}
int count = 0;
field[0] = false;
field[1] = false;
for(int i=2; i<MAX_N; i++){
if(field[i]){
prime[count] = i;
count++;
for(int j=i*2; j<MAX_N; j+=i){
field[j] = false;
}
}
}
int n;
while(cin >> n){
int a=0;
for(int i=0; i<MAX_N; i++){
if(prime[i] < n) a=prime[i];
if(n < prime[i]){
cout << a << " " << prime[i] << endl;
break;
}
}
}
return 0;
}
AOJ Volume0 0083: Era Name Transformation
年、月、日を一つの数値として管理した。
/***************************
* 2012/07/09 *
* AOJ_Volume0_0083 *
* Era Name Transformation *
* crane *
****************************/
//-----------------------------------//
// meiji 1868.09.08 ~ 1912.07.29 //
// taisho 1912.07.30 ~ 1926.12.24 //
// showa 1926.12.25 ~ 1989.01.07 //
// heisei 1989.01.08 ~ //
//-----------------------------------//
#include<iostream>
using namespace std;
int main(){
int y, m, d;
while(cin >> y >> m >> d){
int data = 0;
data = (y * 10000) + (m * 100) + d;
if(data <18680908)
cout << "pre-meiji" << endl;
else if(18680908 <= data && data <= 19120729)
cout << "meiji " << (y - 1868 + 1) << " " << m << " " << d << endl;
else if(19120730 <= data && data <= 19261224)
cout << "taisho " << (y - 1912 + 1) << " " << m << " " << d << endl;
else if(19261225 <= data && data <= 19890107)
cout << "showa " << (y - 1926 + 1) << " " << m << " " << d << endl;
else if(19890108 <= data)
cout << "heisei " << (y - 1989 + 1) << " " << m << " " << d << endl;
}
return 0;
}
/***************************
* 2012/07/09 *
* AOJ_Volume0_0083 *
* Era Name Transformation *
* crane *
****************************/
//-----------------------------------//
// meiji 1868.09.08 ~ 1912.07.29 //
// taisho 1912.07.30 ~ 1926.12.24 //
// showa 1926.12.25 ~ 1989.01.07 //
// heisei 1989.01.08 ~ //
//-----------------------------------//
#include<iostream>
using namespace std;
int main(){
int y, m, d;
while(cin >> y >> m >> d){
int data = 0;
data = (y * 10000) + (m * 100) + d;
if(data <18680908)
cout << "pre-meiji" << endl;
else if(18680908 <= data && data <= 19120729)
cout << "meiji " << (y - 1868 + 1) << " " << m << " " << d << endl;
else if(19120730 <= data && data <= 19261224)
cout << "taisho " << (y - 1912 + 1) << " " << m << " " << d << endl;
else if(19261225 <= data && data <= 19890107)
cout << "showa " << (y - 1926 + 1) << " " << m << " " << d << endl;
else if(19890108 <= data)
cout << "heisei " << (y - 1989 + 1) << " " << m << " " << d << endl;
}
return 0;
}
ラベル:
AOJ,
AOJ_Volume0,
時間,
年号
AOJ Volume10 1041: Kyudo:A Japanese Art of Archery
問題通りに実装すればOK
nの値も4の倍数と親切に決めてくれているので問題なし。
/*********************************
* 2012/07/09 *
* AOJ_Volume10_1041 *
* Kyudo:A Japanese Art of Archery*
* crane *
**********************************/
#include<iostream>
using namespace std;
int main(){
int n;
while(cin >> n, n){
int tmp, sum=0;
for(int i=0; i<n/4; i++){
cin >> tmp;
sum += tmp;
}
cout << sum << endl;
}
return 0;
}
nの値も4の倍数と親切に決めてくれているので問題なし。
/*********************************
* 2012/07/09 *
* AOJ_Volume10_1041 *
* Kyudo:A Japanese Art of Archery*
* crane *
**********************************/
#include<iostream>
using namespace std;
int main(){
int n;
while(cin >> n, n){
int tmp, sum=0;
for(int i=0; i<n/4; i++){
cin >> tmp;
sum += tmp;
}
cout << sum << endl;
}
return 0;
}
2012年7月7日土曜日
AOJ Volume20 2001: Amida the city of Miracle
/***************************
* 2012/07/07 *
* AOJ_Volume20_2001 *
* Amida_the_city_of_Miracle*
* crane *
****************************/
#include<iostream>
using namespace std;
#define MAX_H 1001
#define MAX_N 101
int field[MAX_H][MAX_N];
int main(){
int n,m,a;
while(cin >> n >> m >> a, (n||m||a)){//n:縦線、m:横線、a:調べる縦線
for(int i=1; i<MAX_H; i++){
for(int j=1; j<=n; j++){
field[i][j] = j;
}
}
int h, p, q; //h:横線の高さ p,q:つながっている横線
for(int i=0; i<m; i++){
cin >> h >> p >> q;
field[h][p] = q;
field[h][q] = p;
}
int res= a;
for(int i=MAX_H-1; 0<i; i--){
res = field[i][res];
}
cout << res << endl;
}
return 0;
}
* 2012/07/07 *
* AOJ_Volume20_2001 *
* Amida_the_city_of_Miracle*
* crane *
****************************/
#include<iostream>
using namespace std;
#define MAX_H 1001
#define MAX_N 101
int field[MAX_H][MAX_N];
int main(){
int n,m,a;
while(cin >> n >> m >> a, (n||m||a)){//n:縦線、m:横線、a:調べる縦線
for(int i=1; i<MAX_H; i++){
for(int j=1; j<=n; j++){
field[i][j] = j;
}
}
int h, p, q; //h:横線の高さ p,q:つながっている横線
for(int i=0; i<m; i++){
cin >> h >> p >> q;
field[h][p] = q;
field[h][q] = p;
}
int res= a;
for(int i=MAX_H-1; 0<i; i--){
res = field[i][res];
}
cout << res << endl;
}
return 0;
}
AOJ Volume20 2000: Misterious Games
/*************************
* 2012/07/07 *
* AOJ_Volume20_2000 *
* Misterious_Gems *
* crane *
**************************/
#include<iostream>
using namespace std;
#define FIELD 21
bool field[FIELD][FIELD];
int main(){
int n; //宝石の個数
while(cin >> n, n){
for(int i=0; i<FIELD; i++)
for(int j=0; j<FIELD; j++)
field[i][j] = false;
/*--宝石の位置--*/
int xi, yi;
for(int i=0; i<n; i++){
cin >> xi >> yi;
field[yi][xi] = true;
}
int m; //命令の個数
cin >> m;
char dj;
int lj;
int x = 10, y = 10; //ロボット降下位置
for(int i=0; i<m; i++){
cin >> dj >> lj; //命令取得
while(lj--){
switch (dj){
case 'N':
y++;
break;
case 'E':
x++;
break;
case 'S':
y--;
break;
case 'W':
x--;
break;
}
if(field[y][x]){
n--;
field[y][x] = false;
}
}
}
if(n == 0) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
登録:
投稿 (Atom)


