---
# System prepended metadata

title: C++題解 scist題單

---

# C++題解 scist題單
其實知道怎麼解，只是題目看不懂QQ
## Kattis
### Kattis Hello world!
題目連結: https://open.kattis.com/problems/hello
```cpp=
#include <iostream>
using namespace std ;
int main()
{
    cout << "Hello World!\n" ;
    return 0 ;
}
```
### Kattis Two-sum
題目連結: https://open.kattis.com/problems/twosum
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int a , b ;
    cin >> a >> b ;
	cout << a+b << "\n" ;
	return 0 ;
}
```
### Kattis Jack-O'-Lantern Juxtaposition
題目連結: https://open.kattis.com/problems/jackolanternjuxtaposition
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int a , b , c ;
    cin >> a >> b >> c ;
	cout << a*b*c << "\n" ;
	return 0 ;
}
```
### Kattis Flatbökuveisla
題目連結: https://open.kattis.com/problems/flatbokuveisla
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int n , m ;
    cin >> n >> m ;
	cout << n%m << "\n" ;
	return 0 ;
}
```
### Kattis Saving For Retirement
題目連結: https://open.kattis.com/problems/savingforretirement
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int a , a1 , a2 , b , b2 ;
    cin >> a >> a1 >> a2 >> b >> b2 ;
    int c=(a1-a)*a2 ;
    cout << c/b2+b+1 ;
	return 0 ;
}
```
### Kattis Soylent
題目連結: https://open.kattis.com/problems/soylent
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a , n ;
    cin >> a ;
    for( int i=0 ; i<a ; i++ )
    {
        cin >> n ;
        n=(n+400-1)/400;
        cout << n << "\n" ;
    }  
    return 0 ;
}
```
### Kattis Longest Prime Sum
題目連結: https://open.kattis.com/problems/longestprimesum?tab=submissions
```cpp=
#include <iostream>
using namespace std;
int main()
{
    long long a ;
    cin >> a ;
    if(a%2>0)
    {
        a-=3 ;
        cout << a/2LL+1 << "\n" ;
    }
    else
    {
        cout << a/2LL << "\n";
    }

    return 0;
}
```
### Kattis Crne
題目連結: https://open.kattis.com/problems/crne?tab=submissions
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a;
    cin >> a;
    if(a%2==0)
    {
        cout << (a/2LL+1)*(a/2+1) << "\n";
    }
    else 
    {
        cout << (a/2LL+1)*(a/2+2) <<"\n";
    }
    return 0;
}
```
ㄚㄚㄚ它題目真優秀"strictly more than..."害我想久QQ

### Kattis Arm Coordination
題目連結: https://open.kattis.com/problems/armcoordination
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int x , y , r ;
    cin >> x >> y >> r ;
    cout << x+r << " " << y+r << "\n" ;
    cout << x+r << " " << y-r << "\n" ;
    cout << x-r << " " << y-r << "\n" ;
    cout << x-r << " " << y+r << "\n" ;
    return 0 ;
}
```
### Kattis Stuck In A Time Loop
題目連結: https://open.kattis.com/problems/timeloop
```cpp=
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cout << i+1 << " Abracadabra\n";
	}
	return 0;
}
```
### Kattis Shandy
題目連結: https://open.kattis.com/problems/shandy
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int m , n  ;
    cin >> m >> n ;
    if(m>n && n>0)
    {
        cout << n*2 ;
    }
    else if(n>m && m>0)
    {
        cout << m*2 ;
    }
    else if(n=m && n>0 && m>0)
    {
        cout << m*2 ;
    }
    else
    {
        cout << "0\n" ;
    }
    return 0 ;
}
```

## TOJ
### TOJ 94
題目連結: https://toj.tfcis.org/oj/pro/94/
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int a ;
    cin >> a ;
    if(a==3 || a==4 || a==5)
    {
        cout << "Spring!\n" ;
    }
    else if(a==6 || a==7 || a==8)
    {
        cout << "Summer!\n" ;
    }
    else if(a==9 || a==10 || a==11)
    {
        cout << "Autumn!\n" ;
    }
    else
    {
        cout << "Winter!\n" ;
    }
    return 0;
}
```
### TOJ 98
題目連結: https://toj.tfcis.org/oj/pro/98/
```cpp=
#include<iostream>
using namespace std;
int main()
{
    long long LS ;
    long long LM ;
    long long LH ;
    long long LD ;
    long long LW ;
    long long LY ;
    long long L=299792458 ;
    
    LS=L;
    LM=L*60;
    LH=L*60*60;
    LD=L*60*60*24;
    LW=L*60*60*24*7;
    LY=L*60*60*24*365;
    
    cout << "1 Light-second(LS) is " << LS << " metres.\n" ;
    cout << "1 Light-minute(LM) is " << LM << " metres.\n" ;
    cout << "1 Light-hour(LH) is " << LH << " metres.\n" ;
    cout << "1 Light-day(LD) is " << LD << " metres.\n" ;
    cout << "1 Light-week(LW) is " << LW << " metres.\n" ;
    cout << "1 Light-year(LY) is " << LY << " metres.\n" ;
    
	return 0 ;
}
```
### TOJ 104
題目連結: https://toj.tfcis.org/oj/pro/104/
```cpp=
#include<iostream>
using namespace std;
int main() 
{
    int n ;
    cin >> n ;
    for(int i=0 ; i<n ; i++)
    {
        for(int j=0 ; j<n-1-i ; j++)
        {
            cout<<" " ;
        }
        for(int j=0 ; j<2*(i+1)-1 ; j++)
        {
            cout<<"*" ;
        }
        cout << "\n" ;  
    }
    return 0;
}
```
```cpp
#include<iostream>
using namespace std;
int main()
{
    int n , space , star;
    cin >> n ;
    for (space=n-1, star=1; space>=0; --space, star+=2)
    {
        for (int i=0; i<space; i++)
        {
            cout << " ";
        }
        for (int i=0; i<star; i++)
        {
            cout << "*";
        }
    cout << "\n";
    }
    return 0 ;
}
```
### TOJ 519
題目連結: https://toj.tfcis.org/oj/pro/519/

```cpp=
#include<iostream>
using namespace std ;
int main()
{
    int a , b ;
    cin >> a >> b ;
    cout << "Do you want to say " << a << " and " << b << " ??\n" ;
    return 0 ;
}
```
### TOJ 520
題目連結: https://toj.tfcis.org/oj/pro/520/
```cpp=
#include<iostream>
using namespace std ;
int main()
{
    int a , b ;
    cin >> a >> b ;
	cout << b << " " << a << "\n" ;
	return 0 ;
}
```
### TOJ 521
題目連結: https://toj.tfcis.org/oj/pro/521/
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int a , b ;
    cin >> a >> b ;
	cout << a-b << "\n" ;
	return 0 ;
}
```
### TOJ 522
題目連結: https://toj.tfcis.org/oj/pro/522/
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int x ;
    cin >> x ;
    x*=x ;
    cout << x%10 << "\n" ;
    return 0 ;
}
```
### TOJ 523
題目連結: https://toj.tfcis.org/oj/pro/523/
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int n ;
    cin >> n ;
    n/=10 ;
    cout << n%10 << "\n" ;
    return 0 ;
}
```
### TOJ 524
題目連結: https://toj.tfcis.org/oj/pro/524/
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int a , b ;
    cin >> a >> b ;
    a=(a+b)/2;
    b=b-a;
    cout << "a: "<< a << ", b: " << -b ;
	return 0 ;
}
```
### TOJ 525
題目連結: https://toj.tfcis.org/oj/pro/525/
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a ,b ;
    cin >> a >> b ;
    cout << (a+b)/2 << "\n" ;
    return 0 ;
}
```
### TOJ 526
題目連結: https://toj.tfcis.org/oj/pro/526/
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a=0 , b=0 ;
    cin >> a ;
    while(a)
    {
        b*=10;
        b+=a%10;
        a/=10;
    }
    cout << b << "\n";
    return 0;
}
```

### TOJ 528
題目連結: https://toj.tfcis.org/oj/pro/528/
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a ;
    cin >> a ;
    cout << abs(a) << "\n" ;   
    return 0 ;
}
```
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a ;
    cin >> a ;
    if(a<0)
    {
        cout << -a << "\n" ;
    }
    else
    {
        cout << a << "\n" ;
    }
    return 0 ;
}
```
### TOJ 529
題目連結: https://toj.tfcis.org/oj/pro/529/
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a , b ;
    cin >> a >> b ;
    int i=abs(a-b) ;
    cout << i << "\n" ;
    return 0 ;
}
```
### TOJ 530
題目連結: https://toj.tfcis.org/oj/pro/530/
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a , b ;
    cin >> a >> b ;
    int smaller = min ( a , b ) ;
    int larger = max ( a , b ) ;
    cout << smaller << " " << larger << "\n" ;
    return 0 ;
}
```
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a , b ;
    cin >> a >> b ;
    if(a>b)
    {
        cout << b << " " << a << "\n" ;
    }
    else
    {
        cout << a << " " << b << "\n" ;
    }
    return 0 ;
}
```
### TOJ 531
題目連結: https://toj.tfcis.org/oj/pro/531/
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a , b ;
    cin >> a >> b ;
    if(a<b)
    {
        cout << "true\n" ;
    }
    else
    {
        cout << "false\n" ;
    }
    return 0 ;
}
```
### TOJ 532
題目連結: https://toj.tfcis.org/oj/pro/532/
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int p , q , a=0 , b=0 ;
    cin >> p >> q ;
    if(p%2==0) a++ ;
    if(q%2==0) a++ ;
    if(p%3==0) b++ ;
    if(q%3==0) b++ ;
    cout << a << " " << b << "\n" ; 
    return 0 ;
}
```
### TOJ 533
題目連結: https://toj.tfcis.org/oj/pro/533/
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a , b , n ;
    cin >> a >> b >> n ;
    if(n>=a && n<=b)
    {
        cout << "yes\n" ;
    }
    else
    {
        cout << "no\n" ;
    }
    return 0;
}
```
### TOJ 534
題目連結: https://toj.tfcis.org/oj/pro/534/
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a , b ;
    cin >> a >> b ;
    if(a%2==0 && b%2==0)
    {
        cout << "yes\n" ;
    }
    else if(a%2!=0 && b%2!=0)
    {
        cout << "yes\n" ;
    }
    else
    {
        cout << "no\n" ;
    }
    return 0 ;
}
```
### TOJ 535
題目連結: https://toj.tfcis.org/oj/pro/535/
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a ;
    cin >> a ;
    if(a==100)
    {
        cout << "S\n" ;
    }
    else if(a<=99&&a>=90)
    {
        cout << "A\n" ;
    }
    else if(a<=89&&a>=80)
    {
        cout << "B\n" ;
    }
    else if(a<=79&&a>=70)
    {
        cout << "C\n" ;
    }
    else if(a<=69&&a>=60)
    {
        cout << "D\n" ;
    }
    else
    {
        cout << "F\n" ;
    }
    return 0 ;
}
```
### TOJ 576
題目連結: https://toj.tfcis.org/oj/pro/576/
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int n ;
    cin >> n ;
    int i=0 ;
    while(n!=0)
    {
        i++;
        n=n/10 ;
    }
    cout << i ;
    return 0 ;
}
```
### TOJ 577
題目連結: https://toj.tfcis.org/oj/pro/577/
```cpp=
#include<iostream>
using namespace std;
int main() 
{
    int n ;
    cin >> n ;
    for(int t=0 ; t<n ; t++)
    {
        int a , b ;
        cin >> a >> b ;
        long long ans=1 ;
        for(int i=0 ; i<b ; i++)
        {
            ans*=a;
        }
        cout << ans << "\n" ;
    }
    return 0;
}
```
### TOJ 578
題目連結: https://toj.tfcis.org/oj/pro/578/
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int n ;
    cin >> n ;
    int i=1 ;
    n=n-1;
    while(i<=n)
    {
        cout << i << " \n" ;
        i=i+2 ;
    }
    return 0 ;
}
```
## AtCoder
### AtCoder A-Three Dice
題目連結: https://atcoder.jp/contests/abc202/tasks/abc202_a
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int a , b , c ;
    cin >> a >> b >> c ;
	cout << 7-a+7-b+7-c << "\n" ;
	return 0 ;
}
```
### AtCoder A-Century
題目連結: https://atcoder.jp/contests/abc200/tasks/abc200_a
```cpp=
#include<iostream>
using namespace std;
int main()
{
    int a ;
    cin >> a ;
    cout << (a+100-1)/100 << "\n" ;
	return 0 ;
}
```
### AtCoder A-Rolling Dice
題目連結: https://atcoder.jp/contests/abc208/tasks/abc208_a
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int a , b ;
    cin >> a >> b ;
    int c=a*6 ;
    if( b<=c && b>=a)
    {
        cout << "Yes\n" ;
    }
    else
    {
        cout << "No\n" ;
    }
    return 0;
}
```
### AtCoder A-New Generation ABC
題目連結: https://atcoder.jp/contests/abc214/tasks/abc214_a
```cpp=
#include <iostream>
using namespace std;
int main ()
{
    int n;
    cin >> n ;
    if(n>0 && n<126)
    {
        cout << "4\n" ;
    }
    else if (n>125 && n<212)
    {
        cout << "6\n" ;
    }
    else
    {
        cout << "8\n" ;
    }
    return 0 ;
}
```
### AtCoder A-AtCoder Quiz 2 
題目連結: https://atcoder.jp/contests/abc219/tasks/abc219_a
```cpp!
#include <iostream>
using namespace std;
int main ()
{
    int n;
    cin >> n ;
    if(n>=0 && n<40)
    {
        cout << 40-n << "\n" ;
    }
    if(n>=40 && n<70)
    {
        cout << 70-n << "\n" ; 
    }
    if(n>=70 && n<90)
    {
        cout << 90-n <<"\n" ;
    }
    if(n>=90)
    {
        cout << "expert\n" ;
    }
    return 0 ;
}
```
### AtCoder A-Product 
題目連結: https://atcoder.jp/contests/abc086/tasks/abc086_a 
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int n , m;
    cin >> n >> m;
    n*=m ;
    if(n%2==0)
    {
        cout << "Even\n" ;
    }
    else
    {
        cout << "Odd\n" ;
    }
    return 0 ;
}
```
### AtCoder A-Exact Price 
題目連結: https://atcoder.jp/contests/abc223/tasks/abc223_a
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int n ;
    cin >> n ;
    if(n%100==0 && n!=0)
    {
        cout << "Yes\n" ;
    }    
    else
    {
        cout << "No\n" ;
    }
    return 0 ;
}
```
### AtCoder A-Infinite Coins
題目連結: https://atcoder.jp/contests/abc088/tasks/abc088_a
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int n ,m , o;
    cin >> n >> m;
    n%=500;
    if(m>=n)
    {
        cout << "Yes\n" ;
    }
    else
    {
        cout << "No\n" ;
    }
    return 0 ;
}
```
### AtCoder A-RGB Cards
題目連結: https://atcoder.jp/contests/abc064/tasks/abc064_a
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int m , n , o ;
    cin >> m >> n >> o;
    m*=100;
    n*=10;
    m+=n;
    m+=o;
    if(m%4==0)
    {
        cout << "YES\n" ;
    }
    else
    {
        cout << "NO\n" ;
    }
    return 0 ;
}
```
### AtCoder A-Counting
題目連結: https://atcoder.jp/contests/abc209/tasks/abc209_a
```cpp!
#include <iostream>
using namespace std;
int main()
{
    int m , n  ;
    cin >> m >> n;
    if(m<n)
    {
        cout << n-m+1 ;
    }
    if(m>n)
    {
        cout << "0\n" ;
    }
    return 0 ;
}
```
### AtCoder A-Cabbages
題目連結: https://atcoder.jp/contests/abc210/tasks/abc210_a
```cpp!
#include <iostream>
using namespace std;
int main()
{
    int m , n , o , p  ;
    cin >> m >> n >> o >> p ;
    if(m<=n)
    {
        cout << m*o <<"\n";
    }
    else
    {
        cout << n*o+(m-n)*p <<"\n" ; 
    }
    return 0 ;
}
```
### AtCoder A-Alloy
題目連結: https://atcoder.jp/contests/abc212/tasks/abc212_a
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int n,m ;
    cin >> n >> m ;
    if(n>0 && m==0)
    {
        cout << "Gold\n" ; 
    }
    if(n==0 && m>0 )
    {
        cout << "Silver\n" ;
    }
    if(n>0 && m>0)
    {
        cout << "Alloy\n" ;
    }
    return 0 ;
}
```
### AtCoder A-うるう年
題目連結: https://atcoder.jp/contests/arc002/tasks/arc002_1
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int n ;
    cin >> n ;
    if(n%4==0 && n%100!=0 || n%400==0)
    {
        cout << "YES\n";
    }
    else
    {
        cout << "NO\n";
    }
    return 0 ;
}
```
### AtCoder A-Placing Marbles
題目連結: https://atcoder.jp/contests/abc081/tasks/abc081_a
```cpp=
#include <iostream>
using namespace std;
int main()
{
    int n ,o ,p ,q;
    cin >> n ;
    o=n%10;
    p=n/10%10;
    q=n/100%10;
    if(o>0 && p>0 && q>0)
    {
        cout << "3\n" ;
    }
    else if(o>0 && p>0 && q==0)
    {
        cout << "2\n" ;
    }
    else if(o>0 && p==0 && q==0)
    {
        cout << "1\n" ;
    }
    else if(o==0 && p==0 && q==0)
    {
        cout << "0\n" ;
    }
    else if(o==0 && p>0 && q>0)
    {
        cout << "2\n" ;
    }
    else if(o==0 && p==0 && q>0)
    {
        cout << "1\n" ;
    }
    else if(o==0 && p>0 && q==0)
    {
        cout << "1\n" ;
    }
    else if(o>0 && p==0 && q>0)
    {
        cout << "2\n" ;
    }
    return 0 ;
}
```