show me bug
比较版本号 前者大返回1 后者大返回-1 两者一样大返回0
#include <iostream> #include<string> using namespace std; int compare(string A,string B) { int count_A = 0; int count_B = 0; while( count_A < A.size() || count_B < B.size()) { int A_version = 0; int B_version = 0; //获取A的第一段版本号 while(A[count_A] != '.'&& count_A < A.length()) { A_version = A_version * 10; A_version += A[count_A++] - '0'; } if(count_A < A.size()) count_A ++; //获取B的版本号 while(B[count_B] != '.'&& count_B <B.length()) { B_version = B_version * 10; B_version += B[count_B++]- '0'; } if(count_B < B.size()-1) count_B ++; //判断版本号如果不同就return if(A_version > B_version) { return 1; } else if(A_version < B_version) { return -1; } } if(count_A < A.length() - 1)//A没有访问到结尾 { return 1; } else if(count_B < B.length() - 1)//B { return -1; } else//版本号相同 { return 0; } }
bug留给过去 ac留给明天~
有些遗憾 但已经过去
未来加油
posted on 2020-03-24 21:18 KID_XiaoYuan 阅读(470) 评论(0) 编辑 收藏 举报