杭电 3270 The Diophantine Equation

http://acm.hdu.edu.cn/showproblem.php?pid=3270

The Diophantine Equation

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1146    Accepted Submission(s): 297


Problem Description
We will consider a linear Diaphonic equation here and you are to find out whether the equation is solvable in non-negative integers or not.
Easy, is not it?
 

Input
There will be multiple cases. Each case will consist of a single line expressing the Diophantine equation we want to solve. The equation will be in the form ax + by = c. Here a and b are two positive integers expressing the co-efficient of two variables x and y.
There are spaces between:
1. “ax” and ‘+’
2. ‘+’ and “by”
3. “by” and ‘=’
4. ‘=’ and “c”

c is another integer that express the result of ax + by. -1000000
 

Output
You should output a single line containing either the word “Yes.” or “No.” for each input cases resulting either the equation is solvable in non-negative integers or not. An equation is solvable in non-negative integers if for non-negative integer value of x and y the equation is true. There should be a blank line after each test cases. Please have a look at the sample input-output for further clarification.
 

Sample Input
 
   
2x + 3y = 10 15x + 35y = 67 x + y = 0
 

Sample Output
 
   
Yes. No. Yes. HINT: The first equation is true for x = 2, y = 2. So, we get, 2*2 + 3*2=10. Therefore, the output should be “Yes.”
一道很简单的题目,稍稍细心一些就能很快的AC,(我愚钝呀,弄了好久,后来想想觉得A出来之前大脑是短路状态,,这是为什么啊)需要注意的是输入,处理的话也不是很难。 
AC代码:
#include
#include
#include
#include
using namespace std;

int qiujie(int a,int b,int c)
{
    int x;
    for(x=0; x<=c/a; x++) //枚举x可取的所有可能
    {
        if((c-a*x)%b==0)  //判断是否存在正整数y
        {
            return 1;
        }
    }
    return 0;
}
int main()
{
    int a,b,c,i,j;
    char s1[16],s2[16],ch,cj;
    while(cin>>s1>>ch>>s2>>cj>>c)
    {
        a=b=0;
        for(i=0; i


 

你可能感兴趣的:(字符串)