110,538
社区成员
发帖
与我相关
我的任务
分享
int a = 126;
int b=10;
int c;
int d = Math.DivRem(a, b, out c);
if (c <= 5)
c = 5;
else
{
d = d + 1;
c = 0;
}
int newVal = d * 10 + c; //newVal就是你要获取的结果
void Main()
{
Random rd=new Random();
int i=20;
while(i>0)
{
int m=rd.Next(1,10000);
Console.WriteLine("{0}===>{1}",m,Check(m));
i--;
}
/*
7926===>7930
7336===>7340
1516===>1520
2978===>2980
7799===>7800
2651===>2655
9624===>9625
7829===>7830
1107===>1110
7365===>7370
8029===>8030
3030===>3035
807===>810
2990===>2995
430===>435
9510===>9515
3885===>3890
3519===>3520
7083===>7085
5664===>5665
*/
}
string Check(int m)
{
string last= m.ToString().Substring(m.ToString().Length-1);
string exceptLast=m.ToString().Substring(0,m.ToString().Length-1);
int n= int.Parse(last);
if(n>=5) return string.Concat(int.Parse(exceptLast)+1,0);
else return string.Concat(exceptLast,5);
}
static void change(ref int x)
{
int k = x % 10;
if (k > 5) x += 10-k;
else if (k > 1) x += 5 - k;
}
void change(ref int x)
{
int k = x%10;
if ( k > 5) x -= k;
else if ( k > 1) x = x-k+5;
}