【思路】:找规律,参考的别人的,自己写的挂了。http://blog.youkuaiyun.com/appte/article/details/8227632
【AC代码】:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int T = 0;
cin >> T;
while (T--)
{
int n = 0, m = 0;
cin >> n;
if (n<200)
m = n%150;
else if (n >= 200 && n < 300)
m = n%200;
else if (n >= 300)
m = n%50;
cout << m << endl;
}
return 0;
}
【自己写的WA代码】:1300时候就是错的,应该是0,输出50。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int T = 0;
cin >> T;
while (T--)
{
int n = 0;
cin >> n;
int a = n%150, b = n%200, c = n%350;
if (b >= 150)
b %= 150;
if (c >= 300)
c %= 150;
else if (c >= 200)
c %= 200;
else if (c >= 150)
c %= 150;
if (a < b)
{
if (a < c)
cout << a << " ";
else
cout << c << " ";
}
else
{
if (b < c)
cout << b << " ";
else
cout << c << " ";
}
}
return 0;
}
方法就是错的,几乎没法改。。