夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

とりあえず。

ACしたやつの羅列

AOJ 0104

#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main() 
{
    int h,w;
    while (scanf("%d%d",&h,&w)) {
        if (h==0&&w==0) break;
        vector<string> map;
        for (int i=0; i<h; i++) {
            string in;
            cin>>in;
            map.push_back(in);
        }
        vector<vector<int> > went;
        for (int i=0; i<h; i++) {
            vector<int> num(w,0);
            went.push_back(num);
        }
        int ni=0, nj=0;
        bool flag=false;
        while (map[ni][nj]!='.') {
            if (went[ni][nj]==1) {
                flag=true;
                break;
            }
            went[ni][nj]++;
            if (map[ni][nj]=='>') {
                nj++;
            }
            else if (map[ni][nj]=='<') {
                nj--;
            }
            else if (map[ni][nj]=='^') {
                ni--;
            }
            else if (map[ni][nj]=='v') {
                ni++;
            }
        }
        if (flag) printf("LOOP\n");
        else printf("%d %d\n",nj,ni);
    }
}

AOJ 0101

#include <iostream>
#include <string>
using namespace std;
int main() 
{
    string tmp;
    int n;
    cin>>n;
    for (int i=0; i<n; i++) {
        getline(cin,tmp);
        while (tmp=="") getline(cin,tmp);
        while (tmp.find("Hoshino")!=string::npos) {
            tmp.replace(tmp.find("Hoshino"),7,"Hoshina");
        }
        cout<<tmp<<endl;
    }
}

AOJ 0103

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() 
{
    int n;
    scanf("%d",&n);
    for (int ix=0; ix<n; ix++) {
        int out=0,score=0;
        int hit[] = {0,0,0};
        string event;
        while (out<3) {
            cin>>event;
            if (event=="HIT") {
                if (hit[2]==1) score++;
                if (hit[1]==1) hit[2]=1;
                if (hit[0]==1) hit[1]=1;
                hit[0]=1;
            }
            else if (event=="HOMERUN") {
                for (int i=0; i<3; i++) {
                    score+=hit[i];
                    hit[i]=0;
                }
                score++;
            }
            else if (event=="OUT") {
                out++;
            }
        }
        printf("%d\n",score);
    }
}

AOJ 0102

#include <cstdio>
#include <vector>
using namespace std;
int main() 
{
    int n;
    while (scanf("%d",&n)&&n!=0) {
        vector<vector<int> > map;
        for (int i=0; i<n; i++) {
            vector<int> in(n+1);
            in[n]=0;
            for (int j=0; j<n; j++) {
                scanf("%d",&in[j]);
                in[n]+=in[j];
            }
            map.push_back(in);
        }
        vector<int> sum(n+1,0);
        for (int i=0; i<n+1; i++) {
            for (int j=0; j<n; j++) {
                sum[i]+=map[j][i];
            }
        }
        map.push_back(sum);
        for (int i=0; i<n+1; i++) {
            for (int j=0; j<n+1; j++) {
                printf("%5d",map[i][j]);
            }
            printf("\n");
        }
    }
}

PKU 1326

入力が難しいとかシラネ。ちょっとカンニング

#include <string>
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
    string t1,t2;
    int mile;
    char cs;
    while (cin>>t1&&t1!="#") {
        int mileage=0;
        cin>>t2>>mile>>cs;
        if (cs=='B') {
            if (mile%2==0) mileage+=mile*1.5;
            else mileage+=mile*1.5+1;
        }
        else if (cs=='F') {
            mileage+=mile*2;
        }
        else if (cs=='Y') {
            if (mile<=500) mile=500;
            mileage+=mile;
        }
        while (cin>>t1&&t1!="0") {
            cin>>t2>>mile>>cs;
            if (cs=='B') {
                if (mile%2==0) mileage+=mile*1.5;
                else mileage+=mile*1.5+1;
            }
            else if (cs=='F') {
                mileage+=mile*2;
            }
            else if (cs=='Y') {
                if (mile<=500) mile=500;
                mileage+=mile;
            }
        }
        printf("%d\n",mileage);
    }
}

こんぐらい。

広告を非表示にする