//用的C原语言,虽然看着像C++
//我只能下载第一个错的数据,是一个整数时,刚开始没发现没有回车【吐血】,可我的下面的算法要根据那个回车判断(因为我想,只输入一个整数也要打回车键,可人家/就没有,因为是从文件读写)
\
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
void overturn_print(char *);
int main() {
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
char a[100], b[100];
char ch;
scanf("%[0-9]", a);
ch = getchar();
if (ch == '.' || ch == '/') {
scanf("%[0-9]", b);
overturn_print(a);
cout << ch;
overturn_print(b);
}
else if (ch == '%') {
overturn_print(a);
cout << ch;
}
else if (ch == '\n' || ch == -1) {//怎么都不打回车,直接就是一个数字
overturn_print(a);
}
return 0;
}
void overturn_print(char *a) {
while (*a == '0') a++;//去掉前面的0
int len = strlen(a);
if (len == 0) { //如果只有0
cout << a[-1];
return;
}
while (len>0 && a[--len] == '0');//去掉后面的0
while (len >= 0) cout << a[len--];//逆着输出
}
\
郑大OJ1170拦截导弹
测试输入文件只有一行数字,也没有回车结束,读入到文件结束
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e4 + 7;
int myInts[maxn]; //j表示以aryInt[i]为最小值得最长非上升子序列的长度
int dp[maxn];//dp[i]表示长度为j的最长非上升子序列的最小元素(尽可能大)
bool comp(int a, int b) {
return a > b;
}
int LNIS(int aryInt[], int n) {
dp[0] = 0x7f7f7f7f;
dp[1] = aryInt[0];
int nMaxLnis = 1;
for (int i = 1; i < n; ++i) {
int j = (int)(upper_bound(dp, dp + nMaxLnis + 1, aryInt[i], comp) - dp);
if (j > nMaxLnis) {
nMaxLnis = j;
dp[j] = aryInt[i];
}
else if (dp[j - 1] >= aryInt[i] && aryInt[i] > dp[j]) {
dp[j] = aryInt[i];
}
}
return nMaxLnis;
}
int main() {
int n = 0, num = 0;
char ch = getchar();
while(ch != '\n' && ch != '\r' && ch != '\377') {
if (ch == ' ') {
myInts[n++] = num;
num = 0;
}
else {
num = num * 10 + ch - '0';
}
ch = getchar();
}
myInts[n++] = num;
printf("%d\n", LNIS(myInts, n));
return 0;
}
\
\
\