ITSA [C_MM058-中] 二項式求解

Problem

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?a=1005

Thinking

TODO

Solution

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

int main(){
    
    int a,b,c;
    char str[256]="";

    char *temp;
    while(cin >> str){
        
        // 處理輸入
        temp = strtok(str,",");
        a = atoi(temp);
        for(int i = 0 ; i < 2 ; i++){
            temp = strtok(NULL,",");
            if(i==0){
                b = atoi(temp);
            }else if(i==1){
                c = atoi(temp);
            }
        }
        
        // 計算答案
        for(int i = 0 ; i <= c/a ; i++){
            if((c-a*i) % b == 0)
                cout << i << "," << (c-a*i) / b << endl;
        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容