http://poj.org/problem?id=3617
上記のリンクの問題を考えていたのですがどの辺りにエラーが発生しているのかわからなくて困っているので良かったら見ていただきたいです。
条件としては
Input
- Line 1: A single integer: N
- Lines 2..N+1: Line i+1 contains a single initial ('A'..'Z') of the cow in the ith position in the original line
一番最初の行は文字列の個数
次の行から一文字ずつ記入していく
Output
The least lexicographic string he can make. Every line (except perhaps the last one) contains the initials of 80 cows ('A'..'Z') in the new line.
そして80行ごとに改行を行う(おそらく)
エラーとしてはwrong answerとしか出ないのでコンパイルエラーや時間が足りないなどのエラーはないと考えています。
終端文字の格納の仕方や題意に沿ってない部分がありましたら指摘いただきたいです
Input
6
A
C
D
B
C
B
Output
ABCBCD
ソースコード
C++ #include <iostream> #include <algorithm> #include <vector> using namespace std; const int N = 2000; int n; int i,j; int flag=0; char s[N+1]; char e[N+1]; char l; int main(){ scanf("%d",&n); for(int p=0;p<n;p++){ scanf("%c",&l); scanf("%c",&s[p]); } i=0;j=n-1; while(i<=j){ if(s[i]<s[j]){ e[flag]=s[i]; i++; } else { e[flag]=s[j]; j--; } flag++; } for(i=0;i<n;i++){ printf("%c",e[i]); } printf("\n"); return 0; }
よろしければご教授していただきたいです。
回答1件
あなたの回答
tips
プレビュー