2020年7月31日 星期五

10242 - Fourth Point !!

程式碼:
#include <iostream>
#include <iomanip>
using namespace std;
typedef struct
{
    double x,y;
}Point;
int main()
{
    Point p1,p2,p3,p4;
    cout<<fixed<<setprecision(3);
    while(cin>>p1.x>>p1.y>>p2.x>>p2.y>>p3.x>>p3.y>>p4.x>>p4.y)
    {
        if(p1.x==p3.x&&p1.y==p3.y) swap(p1,p2);
        else if(p1.x==p4.x&&p1.y==p4.y) swap(p1,p2),swap(p3,p4);
        else if(p2.x==p4.x&&p2.y==p4.y) swap(p3,p4);
        Point p5;
        p5.x=p1.x+p4.x-p2.x;
        p5.y=p1.y+p4.y-p2.y;
        cout<<p5.x<<" "<<p5.y<<endl;
    }
    return 0;
}

2020年7月30日 星期四

【Hamilton】You'll Be Back 歌詞筆記

hurl:丟
go by:經過
estrangement:疏遠;隔閡
time will tell:時間會證明一切
serve ...... well:對人有所幫助、助益
through it all:經歷一切
when push comes to shove:一旦不得已時
change the subject:改變話題
subject:話題、臣民
until my dying day:一直到死

c660: 墨西哥波浪舞

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    getline(cin,s);
    for(int i=0;i<s.size();i++)
    {
        if(s[i]==' ')
        {
            //cout<<s<<endl;
            continue;
        }
        for(int j=0;j<s.size();j++)
        {
            if(s[j]==' ') cout<<s[j];
            else if(i==j) // capital
            {
                if('a'<=s[j]&&s[j]<='z') cout<<char(s[j]-'a'+'A');
                else cout<<s[j];
            }
            else //non-capital
            {
                if('a'<=s[j]&&s[j]<='z') cout<<s[j];
                else cout<<char(s[j]-'A'+'a');
            }
        }
        cout<<endl;
    }
    return 0;
}

10056 - What is the Probability ?

程式碼:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
    double s,n,p,k,q;
    cin>>s;
    cout<<fixed<<setprecision(4);
    while(s--)
    {
        double r,a0;
        cin>>n>>p>>k;
        q=1-p;
        if(pow(q,n)==1) 
            cout<<"0.0000"<<endl;
        else
            cout<<p*pow(q,k-1)/(1-pow(q,n))<<endl;
    }
    return 0;
}

10038 - Jolly Jumpers

程式碼:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n,tmp;
    while(cin>>n)
    {
        vector<int> sq;
        vector<int> diff;
        for(int i=0;i<n;i++)
        {
            cin>>tmp;
            sq.push_back(tmp);
        }
        for(int i=0;i<sq.size()-1;i++)
            diff.push_back(abs(sq[i]-sq[i+1]));
        sort(diff.begin(),diff.end());
        int i;
        for(i=0;i<n-1;i++)
        {
            if(i+1!=diff[i]) break;
        }
        if(i==n-1) cout<<"Jolly"<<endl;
        else cout<<"Not jolly"<<endl;
        
    }
    return 0;
}

2020年7月29日 星期三

10041 - Vito's Family

程式碼:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int r,cases,n,mid;
    cin>>cases;
    while(cases--)
    {
        cin>>r;
        vector<int> nightbor;
        for(int i=0;i<r;i++)
        {
            cin>>n;
            nightbor.push_back(n);
        }
        sort(nightbor.begin(),nightbor.end());
        mid=r/2;
        int sum=0;
        for(int i=0;i<nightbor.size();i++)
        {
            sum+=abs(nightbor[i]-nightbor[mid]);
        }
        cout<<sum<<endl;
    }
    return 0;
}

10190 - Divide, But Not Quite Conquer!

程式碼:
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        vector<int> sq;
        if(n<=1||m<=1)
        {
            cout<<"Boring!"<<endl;
            continue;
        }
        while(n%m==0)
        {
            sq.push_back(n);
            n/=m;
        }
        if(n!=1) cout<<"Boring!"<<endl;
        else
        {
            for(int i=0;i<sq.size();i++)
            {
                if(i!=sq.size()-1)
                    cout<<sq[i]<<" ";
                else
                    cout<<sq[i]<<" 1"<<endl;
            }
        }
    }
    return 0;
}

2020年7月28日 星期二

【Hamilton】The Room Where It Happens 歌詞筆記

Secretary:部長
good old:有名的人
renamed ... after:把...重新命名為...
whatever it takes:不惜代價
hate the sin, love the sinner:(甘地名言)
Virginians:維吉尼亞人
diametrically opposed:完全相反的
Bros:兄弟
unprecedented:史無前例的
pièce de résistance:最重要的事
how the sausage gets made:私底下做的事
doorstep:門口
disarray:混亂
nowhere else to turn:無處容身
join the fray:參與辯論
pieces:棋
grapple with sth:設法克服
quid pro quo:交換條件
see how it goes:看看事情會怎麼發展
In God we trust:(美國格言)我們信仰上帝
sell ...... down the river:出賣、背叛
skin in the game:(商業上)參與某事
outlive:活得比....長
fall for:相信
hold one’s nose:睜一隻眼閉一隻眼
save the day:扭轉危機
get a say:參與活動並影響或做出決策
trade away:賣掉、出賣

10221 - Satellites

解題心得:
弧長=2*pi*半徑*a/360
弦長=2*sin(a/2)*半徑

pi 可用2acos0得知
三角函數參數預設弧度,轉為角度要另外乘上pi/180

程式碼:
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;

#define PI 2*acos(0)

int main()
{
    double s,a;
    string type;
    cout<<fixed<<setprecision(6);
    while(cin>>s>>a>>type)
    {
        if(a>180) a=360-a;
        if(type=="min") a/=60;
        cout<<2*PI*(s+6440)*(a/360.0)<<" "<<2*sin(a/2.0*PI/180)*(6440+s)<<endl;
    }
    return 0;
}

272 - TEX Quotes

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int count=0;
    string text;
    while(getline(cin,text))
    {
        for(int i=0;i<text.size();i++)
        {
            if(text[i]=='"')
            {
                if(count%2==0) cout<<"``";
                else cout<<"''";
                count++;
            }
            else
                cout<<text[i];
        }
        cout<<endl;
    }
    return 0;
}

2020年7月27日 星期一

10235 - Simply Emirp

程式碼:
#include <iostream>
#include <cmath>
using namespace std;

int isPrime(int n)
{
    for(int i=2;i<=n/2;i++)
    {
        if(n%i==0)
            return 0;
    }
    return 1;
}

int main()
{
    int n;
    while(cin>>n)
    {
        int reverse=0,copy=n;
        while(copy>0)
        {
            reverse=reverse*10+copy%10;
            copy/=10;
        }
        if(isPrime(n)&&isPrime(reverse)&&n!=reverse)
            cout<<n<<" is emirp."<<endl;
        else if(isPrime(n))
            cout<<n<<" is prime."<<endl;
        else
            cout<<n<<" is not prime."<<endl;
    }
    return 0;
}

10226 - Hardwood Species

程式碼:
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;


int main()
{
    int cases;
    cin>>cases;
    string tree,ignore;;
    getline(cin,ignore);
    cin.ignore();
    for(int i=0;i<cases;i++)
    {
        vector<string> species;
        vector<int> amounts;
        int total=0;
        while(getline(cin,tree))
        {
            if(tree.size()==0) break;
            total++;
            int l=0;
            for(l=0;l<species.size();l++)
            {
                if(species[l]==tree)
                {
                    amounts[l]++;
                    break;
                }
            }
            if(l==species.size())
            {
                species.push_back(tree);
                amounts.push_back(1);
            }
        }
        for(int j=0;j<species.size();j++)
        {
            for(int k=0;k<species.size();k++)
            {
                if(species[j]<species[k])
                {
                    swap(species[j],species[k]);
                    swap(amounts[j],amounts[k]);
                }
            }
        }
        for(int j=0;j<species.size();j++)
            cout<<species[j]<<" "<<fixed<<setprecision(4)<<amounts[j]/float(total)*100<<endl;
        if(i!=cases-1)
            cout<<endl;
    }
    return 0;
}

2020年7月25日 星期六

490 - Rotating Sentences

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int l=0,w=0;
    string s[100],temp;
    while(getline(cin,temp))
    {
        s[l++]=temp;
        if(temp.size()>w) w=temp.size();
    }
    for(int i=0;i<w;i++)
    {
        for(int j=l-1;j>=0;j--)
        {
            if(s[j].size()>i)
                cout<<s[j][i];
            else
                cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}

11461 - Square Numbers

程式碼:
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        if(a==0&&b==0) break;
        int sum=0;
        for(int i=a;i<=b;i++)
        {
            int sr=sqrt(i);
            if(sr*sr==i)
                sum++;
        }
        cout<<sum<<endl;
    }
    return 0;
}

2020年7月24日 星期五

10931 - Parity

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int l;
    while(cin>>l)
    {
        int parity=0;
        string binary;
        if(l==0) break;
        cout<<"The parity of ";
        while(l>0)
        {
            binary=(l%2==0?"0":"1")+binary;
            if(l%2) parity++;
            l/=2;
        }
        cout<<binary<<" is "<<parity<<" (mod 2)."<<endl;
    }
}

10252 - Common Permutation

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string a,b;
    while(getline(cin,a))
    {
        getline(cin,b);
        int index1[26]={0},index2[26]={0};
        for(int i=0;i<a.size();i++)
            index1[a[i]-'a']++;
        for(int i=0;i<b.size();i++)
            index2[b[i]-'a']++;
        for(int i=0;i<26;i++)
        {
            if(index1[i]&&index2[i])
            {
                int len=index1[i]<index2[i]?index1[i]:index2[i];
                for(int j=0;j<len;j++)
                    cout<<char('a'+i);
            }
        }
        cout<<endl;
    }
}

10170 - The Hotel with Infinite Rooms

程式碼:
#include <iostream>
using namespace std;

int main()
{
    unsigned long long int s,d;
    while(cin>>s>>d)
    {
        unsigned long long int days=0;
        while(days<d)
        {
            days+=s;
            s++;
        }
        cout<<s-1<<endl;
    }
}

2020年7月23日 星期四

f148: 2. 定向越野 (Orienteering)

程式碼:
#include <iostream>
using namespace std;

int main()
{
    int w,h,n,target=0;
    cin>>w>>h>>n;
    char map[10][10];
    for(int i=0;i<w;i++)
    {
        for(int j=0;j<h;j++)
        {
            cin>>map[i][j];
            if(map[i][j]!='0') target++;
        }
    }
    if(n>target) cout<<"Mission fail."<<endl;
    else
    {
        char object='a';
        for(int i=0;i<26;i++)
        {
            for(int j=0;j<w;j++)
            {
                for(int k=0;k<h&&n>0;k++)
                {
                    if(map[j][k]==char(object+i))
                    {
                        cout<<j<<" "<<k<<endl;
                        n--;
                        break;
                    }
                }
            }
        }
    }
}

10922 - 2 the 9s

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    while(cin>>s)
    {
        if(s=="0") break;
        cout<<s<<" is ";
        int times=1,sum=0;
        for(int i=0;i<s.size();i++)
            sum+=s[i]-'0';
        while(sum>=10)
        {
            times++;
            int copy=0;
            while(sum>0)
            {
                copy+=sum%10;
                sum/=10;
            }
            sum=copy;
        }
        if(sum!=9) cout<<"not a multiple of 9."<<endl;
        else cout<<"a multiple of 9 and has 9-degree "<<times<<".\n";
    }
}

11332 - Summing Digits

程式碼:
#include <iostream>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0) break;
        while(n>=10)
            n=n%10+n/10;
        cout<<n<<endl;
    }
}

2020年7月22日 星期三

【Hamilton】My Shot 歌詞筆記

shot:機會、子彈
scrappy:好鬥
I got a lot of brains but no polish:我的才智尚未被開發、得以展現(?)
"I take "polish" a bit differently.

I think it means he is unrefined. Like he's smart but has no presence or ability to convey it yet. He needs polishing via formal education, to make the most of the intelligence he knows he possesses.

We all know those kids and adults who are clearly smart but don't quite put it together to make the most of their abilities. I think that's what he's saying here."--from here
brag:誇耀
holler:大聲喊叫
drop knowledge:To give information or share knowledge on a subject or just life in general(?)
diamond in the rough:未經琢磨的鑽石
coal:煤炭
unimpeachable:無可挑剔的
brandish:(興奮或威脅的)揮舞
famished:很餓的
fan the flames:搧風點火    ->fan this spark into a flame:讓星星之火燎原
spell out my name:拼出我的名字
we are meant to be:我們命中注定要在一起/一見如故
shit on:輕蔑、不尊重的對待
spending spree:揮霍
Enter me, he says in parentheses:劇本裡會在括號內標註人物出場
"It’s a play on a stage direction. A script will say enter: character and stage directions (non-dialogue) are written in parentheses."--from here
lay down my life:為....貢獻生命
ascendancy:權勢顯赫
take a shot:嘗試、乾杯(此處雙關?)
monarchy:君主制
anarchy:無政府狀態
panicky:驚慌的
tailor:裁縫
y'all: equal to "you all"
knucklehead:笨蛋、榆木腦袋、楞頭青
in loco parentis:(對別人的小孩)代盡父母的責任
in bondage:受奴役
do or die:孤注一擲
sally:突圍
stallion:種馬
battalion:(軍隊的)營
keep out of:別捲入
fraught:令人焦慮不安的
lancelot:一名圓桌武士的名字
hatch a plan:策劃一個決策
the pot calling the kettle black:五十步笑百步 ->歌詞是"blacker than the kettle callin' the pot"
pop a squat:坐下(?)
conventional wisdom:a generally accepted theory or belief.
manumission:奴隸解放
abolitionists:廢奴主義者
ammunition:彈藥
shoot off at the mouth:話講太多、不加思索
rooftop:屋頂
rise up:改變、反抗政府
living on your knees:屈膝苟活
flask:酒瓶
plenty:足夠
Scratch that:收回、忽略之前說的
take a stand:採取堅定立場
vengeance:復仇
defendant:被告人
in the face of:面對
casualties:傷亡

f147: 1. 點餐系統 (Ordering System)

程式碼:
#include <string>
#include <iostream>
using namespace std;

int main()
{
    int command,sum=0,order;
    string menu1[5]={"Medium Wac","WChicken Nugget","Geez Burger","ButtMilk Crispy Chicken","Plastic Toy"};
    string menu2[4]={"German Fries","Durian Slices","WcFurry","Chocolate Sunday"};
    int price1[5]={4,8,7,6,3},price2[4]={2,3,5,7};
    while(cin>>command)
    {
        if(command==0) break;
        else if(command==1)
        {
            cin>>order;
            cout<<menu1[order-1]<<" "<<price1[order-1]<<endl;
            sum+=price1[order-1];
        }
        else if(command==2)
        {
            cin>>order;
            cout<<menu2[order-1]<<" "<<price2[order-1]<<endl;
            sum+=price2[order-1];
        }
    }
    cout<<"Total: "<<sum<<endl;
    return 0;
}

a741: 10101 - Bangla Numbers

程式碼:
#include <iostream>
#include <iomanip>
using namespace std;
void bangla(unsigned long long int n)
{
    if(n==0) return;
    
    if(n/10000000)
    {
        bangla(n/10000000);
        cout<<" kuti";
        n%=10000000;
    }
    if(n/100000)
    {
        bangla(n/100000);
        cout<<" lakh";
        n%=100000;
    }
    if(n/1000)
    {
        bangla(n/1000);
        cout<<" hajar";
        n%=1000;
    }
    if(n/100)
    {
        bangla(n/100);
        cout<<" shata";
        n%=100;
    }
    if(n) cout<<" "<<n;
}
int main()
{
    int times=1;
    unsigned long long int n;
    
    while(cin>>n)
    {
        cout<<setw(4)<<times++<<".";
        if(n==0) cout<<" 0";
        bangla(n);
        cout<<endl;
    }
    return 0;
}

2020年7月20日 星期一

10019 - Funny Encryption Method

解題思路:
二進位出現的1與0就是十進位轉二進位的過程中,每次除以二的mod值,所以可以不用紀錄二進位轉換結果,一直除然後把有1的情況加起來就好了。

十六進位轉二進位也是一樣,先把十六進位換成十進位,然後一直除2。

程式碼:
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int t,n;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int b1=0,copy,b2=0;
        cin>>n;
        copy=n;
        while(copy>0)
        {
            b1+=copy%2;
            copy/=2;
        }
        
        copy=n;
        int times=0,x2=0;
        while(copy>0)
        {
            x2+=pow(16,times)*(copy%10);
            times++;
            copy/=10;
        }
        copy=x2;
        while(copy>0)
        {
            b2+=copy%2;
            copy/=2;
        }
        cout<<b1<<" "<<b2<<endl;
    }
    return 0;
}

11150 - Cola

程式碼:
#include <iostream>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        cout<<(int)(n*1.5)<<endl;
    }
    return 0;
}

2020年7月19日 星期日

10415 - Eb Alto Saxophone Player

解題思路:
這題我的寫法很不漂亮XD
每一個按法的對十個指頭來說,只有按與不按的差別,就直接把每個音調的按法記錄起來。
核心思想就是比較這次跟下次的按法,如果要「按」,就把次數加1。最後在把當前按法換成下次換法。

感覺可以包裝成函式?

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int t;
    cin>>t;
    getchar();
    string c="0111001111",d="0111001110",e="0111001100",f="0111001000",g="0111000000",
    a="0110000000",b="0100000000",C="0010000000",D="1111001110",E="1111001100",F="1111001000",
    G="1111000000",A="1110000000",B="1100000000";
    for(int i=0;i<t;i++)
    {
        int count[10]={0};
        string s,finger="0000000000";
        getline(cin,s);
        if(s[0]=='c') finger=c;
        else if(s[0]=='d') finger=d;
        else if(s[0]=='e') finger=e;
        else if(s[0]=='f') finger=f;
        else if(s[0]=='g') finger=g;
        else if(s[0]=='a') finger=a;
        else if(s[0]=='b') finger=b;
        else if(s[0]=='C') finger=C;
        else if(s[0]=='D') finger=D;
        else if(s[0]=='E') finger=E;
        else if(s[0]=='F') finger=F;
        else if(s[0]=='G') finger=G;
        else if(s[0]=='A') finger=A;
        else if(s[0]=='B') finger=B;
        for(int j=0;j<10;j++)
        {
            if(finger[j]=='1') count[j]++;
        }
        for(int j=1;j<s.size();j++)
        {
            string next;
            if(s[j]=='c') next=c;
            else if(s[j]=='d') next=d;
            else if(s[j]=='e') next=e;
            else if(s[j]=='f') next=f;
            else if(s[j]=='g') next=g;
            else if(s[j]=='a') next=a;
            else if(s[j]=='b') next=b;
            else if(s[j]=='C') next=C;
            else if(s[j]=='D') next=D;
            else if(s[j]=='E') next=E;
            else if(s[j]=='F') next=F;
            else if(s[j]=='G') next=G;
            else if(s[j]=='A') next=A;
            else if(s[j]=='B') next=B;
            for(int k=0;k<10;k++)
            {
                if(finger[k]=='0'&&next[k]=='1') count[k]++;
            }
            finger=next;
        }
        for(int i=0;i<10;i++)
        {
            if(i!=9)
                cout<<count[i]<<" ";       
            else
                cout<<count[i]<<endl;
        }
    }
    return 0;
}

10050 - Hartals

程式碼:
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int n,p,h,ans=0;
        cin>>n>>p;
        vector<int> party;
        for(int j=0;j<p;j++)
        {
            cin>>h;
            party.push_back(h);
        }
        for(int j=1;j<=n;j++)
        {
            for(int k=0;k<party.size();k++)
            {
                if(j%party[k]==0&&j%7!=6&&j%7!=0)
                {
                    ans++;
                    break;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

2020年7月18日 星期六

11417 - GCD

程式碼:
#include <iostream>

using namespace std;

int GCD(int a,int b)
{
    while((a%=b)!=0&&(b%=a)!=0);
    return a+b;
}
int main()
{
    int N;
    while(cin>>N&&N!=0)
    {
        int G=0;
        for(int i=1;i<N;i++)
        {
            for(int j=i+1;j<=N;j++)
            {
                G+=GCD(i,j);
            }            
        }
        cout<<G<<endl;
    }
    
    return 0;
}

10642 Can You Solve It?

解題思路:
線與線的間隔為等差級數。
注意「1ll」這種寫法。
程式碼:
#include <iostream>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)
        {
            int x1,y1,x2,y2;
            cin>>x1>>y1>>x2>>y2;
            long long int step1=(x1+y1)*(x1+y1+1ll)/2+x1;
            long int step2=(x2+y2)*(x2+y2+1ll)/2+x2;
            cout<<"Case "<<i<<": "<<abs(step1-step2)<<endl;            
        }
    }
    return 0;
}

2020年7月17日 星期五

10222 - Decode the Mad man

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    while(getline(cin,s))
    {
        string index="`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./";
        for(int i=0;i<s.size();i++)
        {
            if(s[i]==' '||s[i]=='\n') cout<<s[i];
            else
            {
                for(int j=0;j<index.size();j++)
                {
                    if(s[i]==index[j])
                        cout<<index[j-2];
                }
            }
        }
        cout<<endl;
    }
    return 0;
}

d681: BinaryCount

程式碼:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    string s;
    
    while(getline(cin,s))
    {
        stringstream ss;
        string one,two,operation;
        ss<<s;
        ss>>one;
        cout<<one;
        while(ss>>operation>>two)
        {
            if(operation=="or") cout<<"||";
            else cout<<"&&";
            cout<<two;
            
            if(operation=="or")
            {
                for(int i=0;i<5;i++)
                {
                    if(one[i]=='1'||two[i]=='1') one[i]='1';
                    else one[i]='0';
                }
            }
            if(operation=="and")
            {
                for(int i=0;i<5;i++)
                {
                    if(one[i]=='1'&&two[i]=='1') one[i]='1';
                    else one[i]='0';
                }
            }
        }
        cout<<" = "<<one<<endl;
    }
    return 0;
}

12250 - Language Detection

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int cases=1;
    string s;
    while(cin>>s)
    {
        if(s=="#") break;
        cout<<"Case "<<cases++<<": ";
        if(s=="HELLO") cout<<"ENGLISH"<<endl;
        else if(s=="HOLA") cout<<"SPANISH"<<endl;
        else if(s=="HALLO") cout<<"GERMAN"<<endl;
        else if(s=="BONJOUR") cout<<"FRENCH"<<endl;
        else if(s=="CIAO") cout<<"ITALIAN"<<endl;
        else if(s=="ZDRAVSTVUJTE") cout<<"RUSSIAN"<<endl;
        else cout<<"UNKNOWN"<<endl;
    }
    return 0;
}

10929 - You can say 11

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string n;
    while(cin>>n)
    {
        if(n=="0") break;
        int even=0,odd=0;
        for(int i=0;i<n.size();i++)
        {
            if(i%2) odd+=n[i]-'0';
            else even+=n[i]-'0';
        }
        if(abs(even-odd)%11==0) cout<<n<<" is a multiple of 11."<<endl;
        else cout<<n<<" is not a multiple of 11."<<endl;
    }
    return 0;
}

11437 - Triangle Fun

解題思路:
所求小三角形面積為大三角形的1/7,推導可以看其他人寫的。
注意面積要為正。
注意四捨五入。

程式碼:
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            double ax,ay,bx,by,cx,cy;
            cin>>ax>>ay>>bx>>by>>cx>>cy;
            double area=fabs(ax*by-ay*bx+bx*cy-by*cx+cx*ay-cy*ax)/14;
            area>=0?area:-1*area;
            cout<<(int)(area+0.5)<<endl;
        }
    }
    return 0;
}

2020年7月16日 星期四

e997: 升旗典禮抽背課文

程式碼:
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

int main()
{
    int n;
    string name,s;
    stringstream ss;
    vector<string> l;
    getline(cin,s);
    cin>>n;
    ss<<s;
    while(ss>>name)
        l.push_back(name);
    cout<<l[l.size()-n]<<endl;
    return 0;
}

d471-0與1的遊戲

解題思路:
模擬二進位制。
n bits 會有 2^n種可能。
每次都加1,然後從尾到頭檢查是否要進位。

程式碼:
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        string s;
        for(int i=0;i<n;i++)
            s+="0";
        for(int i=0;i<pow(2,n);i++)
        {
            cout<<s<<endl;
            s[s.size()-1]++;
            for(int j=s.size()-1;j>=0;j--)
            {
                if(s[j]>'1')
                {
                    s[j-1]++;
                    s[j]='0';
                }
            }
        }
    }
    return 0;
}

10783 - Odd Sum

程式碼:
#include <iostream>
using namespace std;

int main()
{
    int t;
    while(cin>>t)
    {
        for(int i=1;i<=t;i++)
        {
            int a,b,sum=0;
            cin>>a>>b;
            for(int j=a;j<=b;j++)
            {
                if(j%2) sum+=j;
            }
            cout<<"Case "<<i<<": "<<sum<<endl;
        }
    }
    return 0;
}

10812 - Beat the Spread!

解題思路:
照著題目寫的去解就好了。
不可能的情況有:任一隊伍分數小於零、分數不為整數
程式碼:
#include <iostream>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            int s,d,team1,team2;
            cin>>s>>d;
            team1=(s+d)/2;
            team2=(s-d)/2;
            if(team1<0||team2<0||(s+d)%2||abs((s-d)%2))
                cout<<"impossible"<<endl;
            else
            {
                if(team1<team2) swap(team1,team2);
                cout<<team1<<" "<<team2<<endl;
            }
        }
    }
    return 0;
}

10420 - List of Conquests

解題思路:
輸入只要能讀到第一個單字,後面用getline讀進來就可以忽略了。
然後就看現在讀到的國家有沒有記錄過,有就把次數加1,沒有就加進去然後次數為1。
輸出照字典序。

程式碼:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n;
    string s,ignore;
    vector<string> country;
    vector<int> times;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>s;
            cin.ignore();
            getline(cin,ignore);
            if(find(country.begin(),country.end(),s)==country.end()) 
                country.push_back(s),times.push_back(1);
            else
            {
                int l=0;
                for(auto it:country)
                {
                    if(it==s)
                        break;
                    l++;
                }
                times[l]++;
            }
        }
        for(int i=0;i<country.size();i++)
        {
            for(int j=0;j<country.size();j++)
            {
                if(country[i]<country[j])
                {
                    swap(country[i],country[j]);
                    swap(times[i],times[j]);
                }
            }
        }
        for(int i=0;i<country.size();i++)
            cout<<country[i]<<" "<<times[i]<<endl;
    }
    return 0;
}

2020年7月15日 星期三

【Hamilton】Satisfied 歌詞筆記

that's what I'm talking about:幹的好!
give it up for sb:掌聲歡迎
the maid of honor:伴娘
rewind:倒帶
tripping over themselves:大獻殷勤
dreamlike:如夢一般的
pang:痛苦
dang:該死的
aflame:燃燒著的、激動的
strike....as....:讓人覺得
forget oneself:失態
catch:玄機(不確定)
flirt:輕佻
fidget:坐立不安
look askance:不滿地看
fly by the seat of your pants:未經縝密的思考和計畫即採取行動
social climb:提升社會階級
insidious:陰險的
be after:追求
nice going:(嘲諷)幹的好!
size sth/sb up:下判斷

同場加贈:https://www.bilibili.com/video/BV1kx411W7CQ?p=2
(聽了會很helpless)

10071 - Back to High School Physics

解題思路:
先回想國高中物理:

v-t圖直線下所圍面積,即為位移,而題目所求位移為著色區域。
梯形面積公式: (上底+下底)*高/2
在這裡上底可視為2t對應到的速度,下底可視為初速度,高為2t。
又因為為等加速度,且時間間隔固定(0~t, t~2t 都間隔t),根據中點公式:(上底+下底)/2=(初速度+2t對應的速度)/2=v。
所以本題可直接帶入公式:v*高,也就是v*2t

程式碼:
#include <iostream>
using namespace std;

int main()
{
    int v,t;
    while(cin>>v>>t)
    {
        cout<<2*v*t<<endl;
    }
    return 0;
}

10035 - Primary Arithmetic

解題思路:
用string解這題。
用較小數+較大數,先把較小數直接加上較大數,計算出進位次數。
然後再把該數字從頭到尾再檢查過一次要不要進位。
最後就是判斷輸出格式。

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string a,b;
    while(cin>>a>>b)
    {
        if(a=="0"&&b=="0") break;
        int operation = 0;
        if(a.size()>b.size()) swap(a,b);
        for(int i=0;i<a.size();i++)
        {
            b[b.size()-i-1]=b[b.size()-i-1]+a[a.size()-i-1]-'0';
            if(b[b.size()-i-1]>'9')
            {
                b[b.size()-i-1]=(b[b.size()-i-1]-'0')%10+'0';
                b[b.size()-i-2]++;
                operation++;
            }
        }
        for(int i=b.size()-1;i>=0;i--)
        {
            if(b[i]>'9')
            {
                b[i]=(b[i]-'0')%10+'0';
                b[i-1]++;
                operation++;
            }
        }
        
        if(operation==0) cout<<"No carry operation."<<endl;
        else if(operation==1) cout<<"1 carry operation."<<endl;
        else cout<<operation<<" carry operations."<<endl;
    }
    return 0;
}

10055 - Hashmat the Brave Warrior

程式碼:
#include <iostream>
using namespace std;

int main()
{
    long long int a,b;
    while(cin>>a>>b)
    {
        cout<<abs(a-b)<<endl;
    }
    return 0;
}

2020年7月14日 星期二

10062 - Tell me the frequencies!

解題思路:
ascii code總共有128個,對應值為0~127,所以直接用長度為128的一維陣列紀錄出現次數即可。
再來是如何依照要求輸出。
因為每列最大長度為1000,所以單一值最大可能出現次數也是1000,那就從出現1次~1000次慢慢找,並且每次都從ascii最後面找(127~0)。
這樣做比較方便,不用煩惱怎麼排序,反正就次數由少到多、ascii值由大到小輸出。

程式碼:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    while(getline(cin,s))
    {
        int count[128]={0};
        for(int i=0;i<s.size();i++)
            count[s[i]]++;
        for(int i=1;i<=1000;i++)
        {
            for(int j=127;j>=0;j--)
            {
                if(count[j]==i)
                    cout<<j<<" "<<i<<endl;
            }
        }
        cout<<endl;
    }
    return 0;
}

2020年7月13日 星期一

00100 - The 3n + 1 problem

#include <iostream>
using namespace std;

int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        int max_times=1;
        cout<<a<<" "<<b<<" ";
        if(a>b) swap(a,b);
        for(int i=a;i<=b;i++)
        {
            int times=1,n=i;
            while(n!=1)
            {
                times++;
                if(n%2) n=3*n+1;
                else n=n/2;
            }
            if(times>max_times) max_times=times;
        }
        cout<<max_times<<endl;
    }
    return 0;
}

2020年7月12日 星期日

【Hamilton】Non-Stop 歌詞筆記

jury:陪審團
bear with me:忍耐我一下、等一等
trial:訴訟
liberty:民主
Deliberation:審議
beyond a shadow of a doubt:不容置疑
counsel:法律顧問
sing along:一起唱
stalling:耽誤
public service:公職
mediocrities:平庸之才
Convention:會議
indelicate:無禮的
listless:無精打采的
proclamation:宣告
ammunition:彈藥
like it’s going out of style:很有熱情地很快的做
confer:談談
abrasive:粗暴、不友好
succinct:簡潔的
Hear me out:(激烈的辯論時)拜託聽我說!
back the wrong horse:下錯賭注;作錯決策
take a stand:(表達立場)站出來
keep close to my chest:守口如瓶
way/direction the wind blows:看看風向
sailing off:航行
turn of phrase:口才
join forces:聯合起來以達到共同目的
department of state:外交部

10008 - What's Cryptanalysis

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        cin.ignore();
        string text;
        char alphabet[26];
        int count[26]={0};
        for(int j=0;j<26;j++)
            alphabet[j]=(char)('A'+j);
        for(int i=0;i<n;i++)
        {
            getline(cin,text);
            for(int j=0;j<text.size();j++)
            {
                if(isalpha(text[j])&&islower(text[j]))
                    count[text[j]-'a']++;
                else if(isalpha(text[j])&&isupper(text[j]))
                    count[text[j]-'A']++;
            }
        }
        for(int i=0;i<26;i++)
        {
            for(int j=0;j<26;j++)
            {
                if(count[i]>count[j])
                {
                    swap(count[i],count[j]);
                    swap(alphabet[i],alphabet[j]);
                }
                else if(count[i]==count[j]&&alphabet[i]<alphabet[j])
                {
                    swap(count[i],count[j]);
                    swap(alphabet[i],alphabet[j]);
                }
            }
        }
        for(int i=0;i<26;i++)
        {
            if(count[i]>0)
                cout<<alphabet[i]<<" "<<count[i]<<endl;
        }
    }
    return 0;
}

2020年7月9日 星期四

2020年7月8日 星期三

【Hamilton】Alexander Hamilton 歌詞筆記

bastard:私生子
whore:婊子
Scotsman:蘇格蘭人
providence:天意
Impoverished:貧困的
squalor:骯髒的
founding father:開國元勳
self-starter:做事主動的人
charter:契約
kept his guard up:保持警惕
barter:以物易物
reigned:支配
dripping down the drain:付諸東流
temple:太陽穴
refrain:詞曲
testament:驗證
word gets around:消息迅速傳開
Took up a collection:募款
whence:何處
debt-ridden:債台高築
bed-ridden:臥床不起
fend for yourself:自謀生路
retreating:神隱
treatise:論文
astute:精明
destitute:貧困
restitution:補償
clerk:擔任店員
late mother:先母
sugar cane:甘蔗
rum:萊姆酒
bow:船首
wait in the wings:準備就緒
back down:認輸、退後
rep:名譽(reputation)

2020年7月7日 星期二

install ngspice


mkdir release
cd release
../configure --with-x --enable-xspice --disable-debug --enable-cider --with-readline=yes --enable-openmp
make
sudo make install

安裝過程中可能遇到錯誤:
1.error: no acceptable C compiler found in $PATH
yum install Gcc
使用./configure 錯誤configure: error: no acceptable C compiler found in $PATH
2.couldn't find gnu readline headers
yum install readline-devel

繪圖方面問題可能缺少的套件:
readline-devel
libXaw-devel
libX11-devel