AOJ プログラミング入門 トピック#9

#トピック#9
##[ITP1_9_A](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/9/ITP1_9_A)
###単語の検索

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cctype>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {
    string w, t;
    cin >> w;
    transform(w.begin(), w.end(), w.begin(), ::tolower);
    
    int ans=0;
    while(true){
        cin >> t;
        
        if(t=="END_OF_TEXT") break;
        transform(t.begin(), t.end(), t.begin(), ::tolower);
        if(t==w) ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}
```

##[ITP1_9_B](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/9/ITP1_9_B)
###シャッフル

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cctype>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {
    

    while(true){
        string w;
        cin >> w;
        if(w[0] == '-') break;
        
        int t;
        cin >> t;
        rep(i, t){
            int n;
            cin >> n;
            string s = w.substr(0, n);
            w.erase(0, n);
            w = w + s;
        }
        
        cout << w << endl;
    }
    
    return 0;
}
```

##[ITP1_9_C](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/9/ITP1_9_C)
###カードゲーム

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cctype>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {

    int n, ans1=0, ans2=0;
    cin >> n;
    
    rep(i, n){
        string str1, str2;
        cin >> str1 >> str2;
        
        if(str1>str2) ans1+=3;
        else if(str1<str2) ans2+=3;
        else{
            ans1++;
            ans2++;
        }
    }
    
    cout << ans1 << ' ' << ans2 << endl;
    
    return 0;
}
```

##[ITP1_9_D](https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/9/ITP1_9_D)
###文字列変換

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cctype>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {

    string str;
    int q;
    cin >> str >> q;
    
    rep(i, q){
        string cmd;
        cin >> cmd;
        int a, b;
        cin >> a >> b;
        
        if(cmd=="replace"){
            string s;
            cin >> s;
            str = str.replace(a, b-a+1, s);
        }else if(cmd=="reverse"){
            string tmp = str.substr(a, b-a+1);
            reverse(tmp.begin(), tmp.end());
            str = str.replace(a, b-a+1, tmp);
        }else{
            cout << str.substr(a, b-a+1) << endl;
        }
    }
    
    return 0;
}
```