content
stringlengths 19
11k
|
---|
#include <stdio.h>
#define max(x, y) ((x)<(y) ? (y) : (x))
#define min(x, y) ((x)>(y) ? (y) : (x))
#define sqr(x) ((x)*(x))
int main(){
int n; scanf("%d", &n);
int a[105] = {0};
int mini = 200, maxi = -200;
for(int i=1; i<=n; i++){
scanf("%d", a+i);
mini = min(mini, a[i]);
maxi = max(maxi, a[i]);
}
long ans = 100000000;
for(int i=mini; i<=maxi; i++){
long sum = 0;
for(int j=1; j<=n; j++)
sum = sum + (long)(sqr(a[j]-i));
ans = min(ans, sum);
if(!ans) break;
}
printf("%ld\n", ans);
return 0;
}
|
#include<stdio.h>
//23:36
int main(){
long n = 0;
long a[100] = {};
long i = 0;
long j = 0;
long min = 0;
long max = 0;
long cost = 0;
long mincost = -1;
scanf("%ld",&n);
for(i=0;i<n;i++){
scanf("%ld",&a[i]);
}
min = a[0];
max = a[0];
for(i=1;i<n;i++){
if(min > a[i]){
min = a[i];
}
if(max < a[i]){
max = a[i];
}
}
//printf("%ld %ld ",min,max);
for(i=0;min+i<=max;i++){
cost = 0;
for(j=0;j<n;j++){
cost += (a[j] - (min+i))*(a[j] - (min+i));
}
//printf("%ld",cost);
if(mincost > cost || mincost == -1){
mincost = cost;
}
}
printf("%ld",mincost);
return 0;
}
|
i,b;main(a,c){for(;c-b&&c-a&&~c;c=getchar_unlocked(i++))a=b,b=c;printf("%d %d",c-b?c-a?-1:i-2:i-1,c-b&&c-a?-1:i);}
|
#include<stdio.h>
int main(){
int i,g,j,k;
char s[100001];
scanf("%s",s);
for(g=0;s[g]!=0;g++);
for(i=0;i<g-1;i++){
if(s[i]==s[i+1]){
printf("%d %d\n",i+1,i+2);
return 0;
}
}
for(i=0;i<g-2;i++){
if(s[i]==s[i+2]){
printf("%d %d\n",i+1,i+3);
return 0;
}
}
puts("-1 -1");
return 0;
}
|
#include<stdio.h>
#include<string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
char s[100010];
int main(){
gets(s);
int n=strlen(s);
rep(i,0,n-1){
if(s[i]==s[i+1]){
printf("%d %d\n",i+1,i+2);
return 0;
}
if(s[i]==s[i+2]){
printf("%d %d\n",i+1,i+3);
return 0;
}
}
puts("-1 -1");
return 0;
}
|
#include<stdio.h>
#define MAX 100005
int main(){
char s[MAX],*p;
fread(s,sizeof(char),MAX,stdin);
p=s;
while(*p!='\n'){
// printf("%c , %c , %c\n",*p,*(p+1),*(p+2));
if(*p==*(p+1)){
printf("%d %d\n",&*p-s+1,&*p-s+2);
return 0;
}
if(*p==*(p+2)){
printf("%d %d\n",&*p-s+1,&*p-s+3);
return 0;
}
*p++;
}
puts("-1 -1");
}
|
#include <stdio.h>
#include <string.h>
char str[100005];
int isUnb(char *p);
int f(char *p);
int main()
{
int length;
scanf("%s", str);
length = strlen(str);
for (int i = 0; i < length - 1; i++) {
if (f(str + i)) {
printf("%d %d\n", i + 1, i + 2);
return 0;
}
if (isUnb(str + i)) {
printf("%d %d\n", i + 1, i + 3);
return 0;
}
}
printf("-1 -1\n");
return 0;
}
int isUnb(char *p)
{
if (p[0] == p[1] || p[0] == p[2] || p[1] == p[2]) {
return 1;
} else {
return 0;
}
}
int f(char *p)
{
if (p[0] == p[1]) {
return 1;
} else {
return 0;
}
}
|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define INF 10000000000
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
int compare_long(const void *a, const void *b) {
return *(long*)a - *(long*)b;
}
int main() {
long N;
char s[100001];
long i, j;
long ans = INF;
long tmp;
long data[100001];
long a[101];
int l = 1, r = 2;
int count[26] = {0};
int len;
scanf("%s", s);
len = strlen(s);
count[s[l-1] - 'a']++;
count[s[r-1] - 'a']++;
while(r <= len) {
if(count[s[r-1] - 'a'] >= 2) {
printf("%d %d\n", l, r);
return 0;
}
if(r - l >= 2) {
count[s[l-1] - 'a']--;
l++;
} else {
r++;
count[s[r-1] - 'a']++;
}
}
printf("-1 -1\n");
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#define ASC 97
int main(void){
char s[100009];
scanf("%s",s);
//int dist[26][100009];
int i,j,k;
int memo[26];
for(i=0;i<26;i++){
memo[i]=-1;
//memo[i][0]=-1;//初期
//memo[i][1]=0;// i,jのようなもの
//for(j=0;j<100009;j++){
//dist[i][j][0]=-100009;//初期
//dist[i][j][1]=-100009;
//}
}
int moji;
for(i=0;s[i]!='\0';i++){
moji=(int)s[i]-ASC;
if(memo[moji]==-1){
memo[moji]=i;
}else{
//dist[i][ (memo[moji][1]) ][0]=memo[moji]-i+3;//主役文字の数ー脇役文字の数
//dist[i][ (memo[moji][1]) ][1]=memo[moji][0]+1;//そのdistの出発点si
if(i-memo[moji]<=2){
printf("%d %d",memo[moji]+1,i+1);
return 0;
}else{
memo[moji]=i;
}
//memo[moji][0]=i;
//memo[moji][1]+=1;
}
}
/*for(i=0;i<26;i++){
dist[i][(memo[moji][1])][1]=memo[moji][0]+1;
}*/
/*
for(i=0;i<26;i++){
int dp[100009][2];
dp[0]=dist[i][0][0];
if(dp[0]>0){
printf("%d %d",dist[i][0][1],dist[i][1][1]);
}
for(j=1;j<memo[i][1];j++){
if(dp[j-1]+dist[i][j][0]>dist){
printf("%d %d",dist[i][j-1])
}
}
}*/
printf("-1 -1");
return 0;
}
|
long M=1e9+7,f[444][444],u;
i,j,k,a[444],b;
main(N,C){
**f=1;
scanf("%d%d",&N,&C);for(;j<N;)scanf("%d",a+j++);
for(;~scanf("%d",&b);)for(j=a[i++];j<=b;j++)for(u=k=0;k<=C;k++)f[i][k]+=u=(f[i-1][k]+u*j)%M;
printf("%ld",f[N][C]%M);
}
|
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 1000000007
ll n,c;
ll a[410],b[410];
ll dp[410][410];//dp[i][j]=i人目までにj個配ったときの答え
ll cum[410][410];//cum[i][j]=1^i+...+j^i
int main(){
scanf("%lld%lld",&n,&c);
rep(i,0,n)scanf("%lld",a+i);
rep(i,0,n)scanf("%lld",b+i);
rep(i,0,405)rep(j,1,405)cum[i][j]=(cum[i][j-1]+pom(j,i,MOD))%MOD;
dp[0][0]=1;
rep(i,1,n+1)rep(j,0,c+1)rep(k,0,j+1)dp[i][j]=(dp[i][j]+dp[i-1][j-k]*(cum[k][b[i-1]]-cum[k][a[i-1]-1]))%MOD;
printf("%lld",(dp[n][c]+MOD)%MOD);
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007LL
long long dp[410][410]={{0}};
long long prod[410][410]={{0}};
int main() {
int C, i, j, k, N;
int A[410], B[410];
long long p;
scanf("%d%d", &N, &C);
for (i=0;i<N;i++) {
scanf("%d", &A[i]);
}
for (i=0;i<N;i++) {
scanf("%d", &B[i]);
}
for (i=0;i<N;i++) {
for (j=A[i];j<=B[i];j++) {
p = 1;
for (k=0;k<=C;k++) {
prod[i][k] = (prod[i][k] + p) % MOD;
p = (p*j) % MOD;
}
}
}
dp[0][0] = 1;
for(i=0;i<N;i++) {
for (j=0;j<=C;j++) {
for (k=0;k<=j;k++) {
dp[i+1][j] = (dp[i+1][j] + dp[i][j-k]*prod[i][k]) % MOD;
}
}
}
printf("%lld\n", dp[N][C]);
return 0;
}
|
#include <stdio.h>
typedef long long ll;
#define MAX 1000000007
int N, C, A[400], B[400];
ll dp[401][400] = {0};
ll pows[401][401] = {0};
ll culc(int c, int index){
int ci, cs = 0;
ll ret = 0, xi;
if(index == N){ return 1; }
if(dp[c][index]){ return dp[c][index]; }
if(index+1 == N){ cs = c; }
for(ci=cs; ci<=c; ci++){
xi = (MAX + pows[B[index]][ci] - pows[A[index]-1][ci])%MAX;
ret = (ret + (xi*culc(c-ci, index+1))%MAX)%MAX;
}
return dp[c][index] = ret;
}
int main(void){
int i, j;
scanf("%d%d", &N, &C);
for(i=0;i<N;i++){ scanf("%d", &A[i]); }
for(i=0;i<N;i++){ scanf("%d", &B[i]); }
for(i=1;i<=400;i++){
pows[i][0] = 1;
for(j=1;j<=400;j++) pows[i][j] = (pows[i][j-1]*i)%MAX;
}
for(j=0;j<=400;j++){
for(i=2;i<=400;i++){
pows[i][j] = (pows[i][j]+pows[i-1][j])%MAX;
}
}
printf("%lld\n", culc(C, 0));
return 0;
}
|
#include<stdio.h>
#include<stdlib.h>
typedef long long int int64;
const int mod=1000000007;
#define ADD(a,b) ((a)+(b)<mod?(a)+(b):(a)+(b)-mod)
#define MUL(a,b) ((int64)(a)*(b)%mod)
int modPow(int r,int n){
int t=1;
int s=r;
while(n>0){
if(n&1) t=MUL(t,s);
s=MUL(s,s);
n>>=1;
}
return t;
}
void run(void){
int n,c;
scanf("%d%d",&n,&c);
int *a=(int *)calloc(2*n,sizeof(int));
int *b=a+n;
int i,j;
for(i=0;i<2*n;i++) scanf("%d",a+i);
const int m=400+1;
int *pre=(int *)calloc(m*m,sizeof(int));
for(i=1;i<m;i++) pre[i]=1;
for(i=1;i<m;i++){
for(j=1;j<m;j++){
pre[i*m+j]=MUL(pre[(i-1)*m+j],j);
}
}
for(i=0;i<m;i++){
for(j=1;j<m;j++){
pre[i*m+j]=ADD(pre[i*m+j],pre[i*m+j-1]);
}
}
int *dp=(int *)calloc(c+1,sizeof(int));
dp[0]=1;
for(i=0;i<n;i++){
for(j=c;j>=0;j--){
int local=0;
for(int k=0;k<=j;k++){
local=ADD(local,MUL(dp[j-k],ADD(pre[k*m+b[i]],mod-pre[k*m+a[i]-1])));
}
dp[j]=local;
}
}
printf("%d\n",dp[c]);
}
int main(void){
run();
return 0;
}
|
long mod=1e9+7,dp[5005][5005],ans;
s[5005];
main(N,M)
{
scanf("%d%s",&N,s);
M=strlen(s);
dp[0][0]=1;
for(int i=0;i<N;i++)
{
for(int j=0;j<=5000;j++)
{
dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j]*2)%mod;
dp[i+1][j?j-1:0]=(dp[i+1][j?j-1:0]+dp[i][j])%mod;
}
}
ans=dp[N][M];
for(int i=0;i<M;i++)ans=ans*(mod+1)/2%mod;
printf("%d\n",ans);
}
|
#include <stdio.h>
#include <string.h>
typedef long long ll;
#define MOD 1000000007LL
ll dp[2][5001];
int main(void){
int N, i, j;
char buf[5001];
scanf("%d%s", &N, buf);
dp[0][0] = 1;
for(i=0;i<N;++i){
int w = i&1;
dp[1-w][0] = dp[1-w][1] = dp[w][0];
for(j=1;j<=N;++j){
dp[1-w][j-1] = (dp[1-w][j-1]+dp[w][j]*2)%MOD;
dp[1-w][j+1] = dp[w][j];
}
}
printf("%lld\n", dp[N&1][strlen(buf)]);
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)
ll n,m;
ll dp[5010][5010];
//dp[i][j]=i回でj文字になる場合の数
char s[5010];
int main(){
scanf("%lld %s",&n,s);
m=strlen(s);
dp[0][0]=1;
rep(i,0,n)rep(j,0,i+1){
dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j]*2)%MOD;
dp[i+1][max(0,j-1)]=(dp[i+1][max(0,j-1)]+dp[i][j])%MOD;
}
printf("%lld",dp[n][m]*invp(pom(2,m,MOD),MOD)%MOD);
}
|
#include <stdio.h>
#include <string.h>
#define N 5000
#define MD 1000000007
long long power(int a, int k) {
long long b = a, p = 1;
while (k) {
if (k & 1)
p = p * b % MD;
b = b * b % MD;
k >>= 1;
}
return p;
}
int main() {
static char cc[N + 1];
static int dp[N + 1], dq[N + 1];
int n, m, i, j;
scanf("%d%s", &n, cc), m = strlen(cc);
dp[0] = 1;
for (i = 1; i <= n; i++) {
for (j = 0; j <= i; j++)
dq[j] = (j == 0 ? dp[0] + dp[1] : dp[j - 1] * 2LL + (j + 1 < i ? dp[j + 1] : 0)) % MD;
for (j = 0; j <= i; j++)
dp[j] = dq[j];
}
printf("%lld\n", dp[m] * power((MD + 1) / 2, m) % MD);
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007LL
long long dp[5010][5010] = {{0}};
int main() {
int i, j, len, N;
long long exp, prod, t;
char s[5010];
scanf("%d%s", &N, &s);
len = strlen(s);
dp[0][0] = 1;
dp[1][0] = 1; dp[1][1] = 2;
for (i=2;i<=N;i++) {
dp[i][0] = (dp[i-1][0] + dp[i-1][1]) % MOD;
for (j=1;j<i-1;j++) {
dp[i][j] = (2*dp[i-1][j-1] + dp[i-1][j+1]) % MOD;
}
dp[i][i-1] = (2*dp[i-1][i-2]) % MOD;
dp[i][i] = (2*dp[i-1][i-1]) % MOD;
}
// for (i=0;i<=N;i++) {for (j=0;j<=i;j++) printf("%lld\t", dp[i][j]); printf("\n");}
exp = MOD - 1 - len;
prod = 1LL;
t = 2LL;
while (exp) {
if (exp & 1) prod = (prod*t) % MOD;
t = (t*t) % MOD;
exp >>= 1;
}
// printf("2^(%lld) = %lld\n", MOD - 1 - len, prod);
printf("%lld\n", (dp[N][len]*prod)%MOD);
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
typedef long long ll;
const ll mod = (ll)(1e9) + 7;
ll n;
ll len;
char str[5005];
ll dp[5005][5005];
ll solve(ll st_i, ll op_i);
int main()
{
//init
for (int i = 0; i <= 5000; i++) {
for (int j = 0; j <= 5000; j++) {
dp[i][j] = -1;
}
}
scanf("%lld", &n);
scanf("%s", str);
len = (ll)strlen(str);
printf("%lld\n", solve(0, 0));
return 0;
}
ll solve(ll st_i, ll op_i)
{
if (st_i == len && op_i == n) {
return 1;
}
else if (op_i >= n) {
return 0;
}
if (dp[st_i][op_i] != -1) {
return dp[st_i][op_i];
}
dp[st_i][op_i] = solve(st_i + 1, op_i + 1);
if (st_i > 0) {
dp[st_i][op_i] += solve(st_i - 1, op_i + 1) * 2;
}
else {
dp[st_i][op_i] += solve(0, op_i + 1);
}
dp[st_i][op_i] %= mod;
return dp[st_i][op_i];
}
|
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#define MOD_BY UINT32_C(1000000007)
#define INV2 UINT32_C(500000004)
int N,l;
char s[50000];
#if 0
uint32_t modoru_memo[12000][6000]; /* [場所][残り] */
uint32_t modoru_search(int pos, int left) {
uint32_t ret = 0;
if (left == 1) return pos == 1;
if (left == 0) return 1;
if (modoru_memo[pos][left]) return ~modoru_memo[pos][left];
if (pos == 0) {
/* 空文字列にバックスペース */
ret = modoru_search(pos, left - 1);
} else {
/* 戻って進む */
ret = modoru_search(pos - 1, left - 2);
ret += ret; /* 0で進むか1で進むか */
if (ret >= MOD_BY) ret -= MOD_BY;
}
/* 進んで戻る */
ret += modoru_search(pos + 1, left - 2);
if (ret >= MOD_BY) ret -= MOD_BY;
return ~(modoru_memo[pos][left] = ~ret);
}
#endif
uint32_t memo[6000][6000]; /* [位置][残り操作数] */
uint32_t search(int pos, int left) {
uint32_t ret=0;
if (left == 0) return pos == l;
if (memo[pos][left])return ~memo[pos][left];
/* 0または1を入力 */
ret = search(pos + 1, left - 1);
ret += ret;
if (ret >= MOD_BY) ret -= MOD_BY;
/* バックスペースを入力 */
ret += search(pos == 0 ? pos : pos - 1, left - 1);
if (ret >= MOD_BY) ret -= MOD_BY;
return ~(memo[pos][left] = ~ret);
}
int main(void) {
uint32_t tmp;
uint32_t divnum;
if(scanf("%d%49999s",&N,s)!=2)return 1;
l=strlen(s);
/* 何でもいいから入力する */
tmp=search(0, N);
/* 残るところが間違っているものを除く */
divnum=INV2;
while(l>0) {
if(l&1)tmp=((uint64_t)tmp*divnum)%MOD_BY;
divnum=((uint64_t)divnum*divnum)%MOD_BY;
l>>=1;
}
printf("%"PRIu32"\n", tmp);
return 0;
}
|
#include<stdio.h>
int main(){
int x;
scanf("%d",&x);
int l=1,sum=0;
while(l<=x){
sum=sum+l;
l++;
}
printf("%d\n",sum);
}
|
#include<stdio.h>
main()
{
int N,b=0,i;
scanf("%d",&N);
if(N>=0&&N<=100)
{
for(i=0;i<=N;i++)
{
b=b+i;
}
}
printf("%d",b);
}
|
#include <stdio.h>
#include <limits.h>
int main() { int sum=0, x;scanf("%d",&x);
while(x!=0){sum+=x;x--;}
printf("%d",sum);
return 0; }
|
#include <stdio.h>
int main(void){
int n,count;
int ans;
scanf("%d",&n);
ans=0;
for(count=1;count<=n;count++){
ans=ans+count;
}
printf("%d",ans);
}
|
#include<stdio.h>
int main(){
int x,y=0;
scanf("%d",&x);
while(x!=0){y+=x;
x--;
}
printf("%d",y);
return 0;
}
|
#include<stdio.h>
int main()
{
int N,total=0;
scanf("%d",&N);
if(N>=1&&N<=100)
{
total=N*(N+1)/2;
}
printf("%d",total);
}
|
#include<stdio.h>
int main()
{
int a,sum = 0;
scanf("%d",&a); // 3
float pembagi = 2;
int sn = a / pembagi * (2 * 1 + (a-1) * 1);
printf("%d\n",sn);
return 0;
}
|
#include<stdio.h>
int main()
{
int x=0,sum=0,a=0,b=0;
scanf("%d,%d,%d",&a,&x,&b);
while (x<a)
x=x+1;
b=x;
sum=(b+1)*b/2;
printf("%d\n",sum);
}
|
#include<stdio.h>
int main()
{
int N,i,candes=0;
while(scanf("%d",&N)!=EOF){
candes =0;
for(i=1 ; i<=N ; i++){
candes=candes+i;
}
printf("%d\n",candes);
}
return 0;
}
|
#include <stdio.h>
int main()
{
int N=0,M=0,sum=0;
//1<=N<=100
scanf("%d",&N);
for(int M=1;M<=N;M++)
sum+=M;
printf("%d",sum);
return 0;
}
|
#include<stdio.h>
int sum(int s){
int ret;
if(s==1){
ret=1;
}else{
ret=sum(s-1)+s;
}
return ret;
}
int main(void){
int n;
scanf("%d",&n);
printf("%d\n",sum(n));
return 0;
}
|
#include <stdio.h>
int main (void)
{
int i,N,s=0;
scanf("%d",&N);
for(i=0;i<=N;i++)
s=s+i;
printf("%d\n",s);
return 0 ;
}
|
#include<stdio.h>
int main(void)
{
int children,i,candy;
char str[4];
fgets(str,sizeof(str),stdin);
sscanf(str,"%d",&children);
for(i=1;i<=children;i++)
{
candy += i;
}
printf("%d",candy);
return 0;
}
|
char s[99];i;main(a){for(;~(a=getchar());)a-66?s[i++]=a:i>0?s[--i]=0:0;puts(s);}
|
s[];char*p=s+3,*q=s+3;c;main(){for(gets(s);p-->s;)*p-66?!c?*--q=*p:c--:c++;puts(q);}
|
char s[99];c,i,j=80;
main(){
for(i=strlen(gets(s));i--;)s[i]-66?!c?s[--j]=s[i]:c--:c++;
puts(s+j);
}
|
#include<stdio.h>
int f;
char c, ans[11];
int main(){
c=getchar();
while(c!=10){
if(c=='B'){
if(f!=0){ans[--f]=0;}
}else{
ans[f++]=c;
}
c=getchar();
}
printf("%s\n", ans);
}
|
#include<stdio.h>
int main(void){
char s[12],a[12];
int i,c=0;
scanf("%s",s);
for(i=0;s[i]!='\0';i++){
if(s[i]=='B'){
c--;
if(c<0)c=0;
}else{
a[c]=s[i];
c++;
}
}
for(i=0;i<c;i++)printf("%c",a[i]);
puts("");return 0;
}
|
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
int r=0,i;
char s[100010],c[100010];
scanf("%s",s);
for(i=0;s[i];i++){
if(s[i]=='B')r=MAX(r-1,0);
else c[r++]=s[i];
}
c[r]=0;
printf("%s\n",c);
return 0;
}
|
#include <stdio.h>
int main(void){
char str[15];
int i = 0;
while((str[i] = getchar()) != '\n'){
if(str[i] == 'B' && i != 0){
i--;
str[i] = '\0';
continue;
}else if(str[i] == 'B')continue;
i++;
}
str[i] = '\0';
printf("%s\n", str);
return 0;
}
|
#include <stdio.h>
int main()
{
char s[11];
scanf("%s", s);
char output[11] = {};
int i, k;
for (i = 0, k = 0; s[i] != 0; i++) {
if (s[i] == 'B') {
if (k > 0) output[--k] = 0;
} else output[k++] = s[i];
}
printf(output);
fflush(stdout);
return 0;
}
|
#include <stdio.h>
int main() {
char s[10], string[10], c;
int ii = 0;
scanf("%s", s);
for (int i = 0;i < sizeof(s);i++) {
if (s[i] != 'B') {
c = s[i];
string[ii] = c;//フ対策
ii++;
}
else {
if (ii > 0) ii--;
}
}
string[ii] = '\0';
printf("%s\n", string);
}
|
#include<stdio.h>
#include<string.h>
int main(void){
int i,l;
char s[11],o[11]={'\0'};
scanf("%s",s);
for(i=0;i<strlen(s);l=strlen(o),i++){
if(s[i]-48){
if(s[i]-49){
o[l-1]='\0';
}
else o[l]=49;
}
else o[l]=48;
}
printf("%s",o);
return 0;
}
|
#include<stdio.h>
#include<string.h>
char x_x,s[15],ans[15];
int len,len_a;
int main(){
scanf("%s",s);
len=strlen(s);
for(int i=0;i<len;i++){
x_x=s[i];
if(x_x=='B'){
if(len_a>0){
len_a--;
ans[len_a]='\0';
}
}
else{
ans[len_a]=x_x;
len_a++;
}
}
printf("%s",ans);
}
|
#include<stdio.h>
#include<string.h>
int main(void)
{
int i, f=0;
char s[11], c[11];
scanf("%s",s);
for(i=0;i<strlen(s);i++){
if(s[i]!='B'){
c[f]=s[i];
f++;
}
else if(f!=0)
f--;
}
for(i=0;i<f;i++)
printf("%c",c[i]);
printf("\n");
return 0;
}
|
#include<stdio.h>
#include<stdlib.h>
int main(){
char c,str1[2]="0",str2[2]="1",str[100];
int d;
while((c=getchar())!='\n'){
d= strlen(str);
if(c=='0') strcat(str,str1);
if(c=='1') strcat(str,str2);
if(c=='B'){
if(d!=0){
str[d-1]='\0';
}
}
}
printf("%s\n",str);
return 0;
}
|
#include <stdio.h>
int main(void)
{
char s[11] = "";
char a[11] = "";
int i, j;
scanf("%s", s);
for ( i=0, j=0; s[i]!='\0'; i++ ) {
switch ( s[i] ) {
case 'B':
j--;
if ( j < 0 ) j = 0;
break;
default:
a[j++] = s[i];
break;
}
}
a[j] = '\0';
puts(a);
return 0;
}
|
#include<stdio.h>
int main(){
char S[15];
scanf("%s",S);
char reset[15];
int id= 0;
for(int i = 0;S[i]!='\0';i++){
if(S[i]== '0'){
reset[id]= '0';
id++;
}if(S[i]=='1'){
reset[id]='1';
id++;
}if(S[i]=='B'){
if(id>0){
id--;
reset[id]='\0';
}
}
}
reset[id]='\0';
printf("%s\n", reset);
return 0;
}
|
#include<string.h>
#include<stdio.h>
int main()
{
char s[15],a[15];
gets(s);
int len =strlen(s);
int l=0;
for(int i=0;i<len ;i++)
{
if(s[i]=='0'||s[i]=='1')
a[l++]=s[i];
if(s[i]=='B'&&l>=1)
l--;
}
for(int i=0;i<l;i++)
printf("%c",a[i]);
printf("\n");
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
int p;
char str[11],ans[11];
scanf("%s",str);
memset(ans,'\0',sizeof(ans));
p = 0;
for (int i = 0;str[i] != '\0';i++) {
if (str[i] == 'B') {
p--;
if (p < 0) {
p = 0;
}
ans[p] = '\0';
}else {
ans[p++] = str[i];
}
}
printf("%s\n",ans);
return 0;
}
|
#include <stdio.h>
int main(){
char ans[10],moji[10];
int i=0,last=0;
scanf("%s\n",moji);
while(1){
if(moji[i]=='B'){
if (last > 0) last--;
}
else if(moji[i]=='0'||moji[i]=='1'){
ans[last] = moji[i];
last++;
}
else
break;
i++;
}
for(i=0;i<last;i++)
printf("%c",ans[i]);
}
|
#include<stdio.h>
#include<string.h>
main()
{
int i, l, x, j, f;
char a[15], b[15];
scanf("%s", a);
l=strlen(a);
for (i=0, j=0, f=0; i<l; i++)
{
if (a[i]!='B')
{
b[j]=a[i];
j++;
f=0;
}
else
{
if (j>0)
{
j--;
f++;
}
}
}
x=strlen(b);
x=x-f;
for (i=0; i<j; i++)
{
printf("%c", b[i]);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
char s[1024];
char e[1024];
int c = 0;
int i;
if (scanf("%1023s", s) != 1) return 1;
for (i = 0; s[i] != '\0'; i++) {
switch (s[i]) {
case '0':
e[c++] = '0';
break;
case '1':
e[c++] = '1';
break;
case 'B':
if (c > 0) c--;
break;
}
}
e[c] = '\0';
puts(e);
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int top=-1,i,j=0;
int arr[10];
char in[10];
scanf("%s",in);
for(i=0;i<strlen(in);i++)
{
if(in[i]=='0'||in[i]=='1')
arr[j++]=in[i];
if(in[i]=='B'&&j!=0)
j=j-1;
}
for(i=0;i<j;i++)
printf("%c",arr[i]);
}
|
#include<stdio.h>
int main()
{
int i,len,j = 0;
char s[11];
scanf("%s",s);
for(i = 0;s[i] != '\0';i++)
{
if(s[i] == 'B')
{
s[i] = '2';
for(j = i - 1;j >= 0;j--)
{
if(s[j] != '2')
{
s[j] = '2';
break;
}
}
}
}
for(i = 0;s[i] != '\0';i++)
{
if(s[i] != '2')
printf("%c",s[i]);
}
printf("\n");
return 0;
}
|
#include<stdio.h>
#include<string.h>
int main()
{
int i,len,l=0,l1=0,m=0;
char a[50],b[50],c[50];
scanf("%s",a);
len=strlen(a);
for(i=0;i<len;i++)
{
if(a[i]=='0')
{
b[m]='0';
m++;
l=m;
}
else if(a[i]=='1')
{
b[m]='1';
m++;
l=m;
}
else if(a[i]=='B')
{
if(l>0)
{
b[l-1]=' ';
l--;
}
}
}
for(i=0;i<m;i++)
{
if(b[i]!=' ')
{
c[l1]=b[i];
l1++;
}
}
c[l1]='\0';
printf("%s",c);
}
|
#include<stdio.h>
#include <string.h>
void main(){
char str[256];
int i,len,array[10],ind;
ind=0;
scanf("%s",str);
len=strlen(str);
// 入力
for(i=0;i<len;i++){
if(str[i]==48){
array[ind++]=0;
}else if(str[i]==49){
array[ind++]=1;
}else{
if(ind>0) ind--;
}
}
//出力
for(i=0;i<ind;i++){
printf("%d",array[i]);
}
}
|
#include <stdio.h>
int main(void){
char s[11],t[11]={},rev[11];
int b=0;
scanf("%s",s);
int i,j=0;
for(i=0;s[i]!='\0';i++);
while(i>0){
i--;
if((b==0)&&(s[i]!='B')){
rev[j]=s[i];
j++;
}else if(s[i]=='B') b++;
else b--;
}
rev[j]='\0';
j=0;
for(i=0;rev[i]!='\0';i++);
while(i>0){
i--;
t[j]=rev[i];
j++;
}
t[j]='\0';
printf("%s",t);
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(){
int i=0;
int idx=0;
char input[10], output[10];
scanf("%s", input);
for(; i < strlen(input); i++){
if(input[i] == '1'){
output[idx++] = '1';
}else if(input[i] == '0'){
output[idx++] = '0';
}else if(input[i] == 'B'){
if(idx > 0)
idx--;
}
}
output[idx] = '\0';
printf("%s\n", output);
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main()
{
char s[15];
scanf("%s", s);
int idx=0;
char arr[15] = {'\0'};
int len = strlen(s);
for (int i=0; i<len ; i++)
{
if(s[i]=='0')
{
arr[idx]='0';
idx++;
}
else if (s[i]=='1')
{
arr[idx]='1';
idx++;
}
else if (s[i]=='B')
{
if (idx!=0){
idx--;
arr[idx]='\0';
}
}
}
printf("%s", arr);
return 0;
}
|
#include<stdio.h>
int main(void){
int i;
int j = 0;
char Out[100];
char S[100];
scanf("%s", S);
while(S[i] != '\0'){
if(S[i] == '0'){
Out[j++] = '0';
}
if(S[i] == '1'){
Out[j++] = '1';
}
if(S[i] == 'B'){
if (j != 0){
Out[--j] = '\0';
}
}
i++;
}
if(j-1 != '\0')
Out[j] = '\0';
printf("%s\n", Out);
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void){
char s[11];
char ans[11]="";
scanf("%s",s);
int aidx = 0;
for(int i=0; i<strlen(s); i++) {
char c = s[i];
if(c=='B' && strlen(ans)>0){
if(aidx!=0) aidx--;
}else if (c!='B'){
ans[aidx] = c;
aidx++;
}
}
ans[aidx]='\0';
printf("%s",ans);
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(){
char s[11] = {0};
char ans[11] = {0};
int ans_cnt = 0;
scanf("%s", s);
for(int cnt = 0; cnt < strlen(s); cnt++){
if(s[cnt] == '0' || s[cnt] == '1'){
ans[ans_cnt] = s[cnt];
ans_cnt++;
}else{
if(ans_cnt > 0){
ans_cnt--;
ans[ans_cnt] = '\0';
}else{
// do nothing
}
}
}
printf("%s", ans);
printf("\n");
}
|
#include<stdio.h>
#include<string.h>
int main(void)
{
int len = 0,i;
char str[16];
fgets(str,sizeof(str),stdin);
for(i=0;i<strlen(str)-1;i++)
{
switch(str[i])
{
case '0':str[len] = '0';
len++;
break;
case '1':str[len] = '1';
len++;
break;
default :if(len > 0)
{
len--;
}
break;
}
}
for(i=0;i<len;i++)
{
printf("%c",str[i]);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int res[10];
int top = 0;
void push(int x){
res[top] = x;
top++;
}
void pop(){
res[top] = -1;
if(top > 0)top--;
}
int main(void){
char s[11];
int i;
scanf("%s",s);
for(i=0;i<10;i++){
if(s[i]=='0'){
push(0);
}else if(s[i]=='1'){
push(1);
}else if(s[i]=='B'){
pop();
}
}
for(i=0;i<top;i++){
printf("%d",res[i]);
}
printf("\n");
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char res[100];
char *str;
int j;
str = (char *)malloc(sizeof(char) * 15);
scanf("%s", str);
j = 0;
for(int i = 0; i <= strlen(str); i++){
if(str[i] == '0')
res[j] = '0';
if(str[i] == '1')
res[j] = '1';
if(str[i] == 'B'){
if(j == 0)
continue;
j--;
continue;
}
j++;
}
res[j-1] = '\0';
printf("%s", res);
return 0;
}
|
#include <stdio.h>
int main()
{
char str[20], str2[20];
scanf("%s", str);
int ctr = 0;
for(int i = 0; str[i] != '\0'; i++)
{
if(str[i] == '0')
{
str2[ctr] = '0';
ctr++;
} else if(str[i] == '1')
{
str2[ctr] = '1';
ctr++;
} else if(ctr != 0)
{
if(str[i] == 'B')
{
str2[ctr-1] = '\0';
ctr-=2;
}
ctr++;
}
}
str2[ctr] = '\0'; //supaya g ada simbol aneh
printf("%s", str2);
return 0;
}
|
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define rep(index,num) for(int index=0;index<num;index++)
#define eps 1e-15
typedef long long ll;
int main(){
char str[11];
scanf("%s",str);
rep(i,10){
if(str[i]=='B'){
for(int j=i-1;j>=0;j--){
if(str[j]=='0'||str[j]=='1'){
str[j]='X';
break;
}
}
str[i]='X';
}
}
rep(i,10){
if(str[i]=='0'||str[i]=='1'){
printf("%c",str[i]);
}
}
printf("\n");
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void){
char S[11];
scanf("%s",S);
int len=strlen(S),i,j=0,k;
char P[11];
for(i=0;i<len;i++){
P[i]=S[i];
}
for(i=0;i<len;i++){
if(S[i]=='0'||S[i]=='1'){
P[j]=S[i];
j++;
}
else if(S[i]=='B'){
if(j==0);
else{
j--;
P[j]='\0';
}
}
}
P[j]='\0';
printf("%s",P);
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void){
char s[12],buf[12]={0};
scanf("%s",s);
//cntは現時点でのbuf内の要素数
int i,j,cnt=0;
for(j=0;j<strlen(s);j++){
if(s[j]=='0'){
buf[cnt]='0';
cnt++;
}else if(s[j]=='1'){
buf[cnt]='1';
cnt++;
}else{
if(cnt!=0){
buf[cnt-1]=0;
cnt--;
}
}
}
printf("%s\n",buf);
return 0;
}
|
#include <stdio.h>
#include<string.h>
int main(){
char s[15];
int i;
char ans[15]="";
scanf("%s",s);
for(i=0;i<strlen(s);i++){
switch(s[i]){
case'0':
case'1':
ans[strlen(ans)]=s[i];
break;
case'B':
ans[strlen(ans)-1]='\0';
break;
default:
break;
}
}
printf("%s\n",ans);
return 0;
}
|
#include <string.h>
#include <stdio.h>
#define REP(i, a, b) for(long long int i = a; i < b; i++)
int main(void) {
char s[20], a[20] = "";
int co = 0;
scanf("%s", s);
REP(i, 0, strlen(s)) {
if (s[i] == '0') {
strcat(a, "0");
co++;
} else if (s[i] == '1') {
strcat(a, "1");
co++;
} else if (s[i] == 'B' && co != 0) {
co--;
a[co] = '\0';
}
}
puts(a);
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
char s[11];
int a[20];
for(int i=0;i<=19;i++){
a[i]=0;
}
scanf("%s",s);
int count=0;
for(int i=0;s[i]!='\0';i++){
if(s[i]=='0'){
a[count]=0;count++;
}
else if(s[i]=='1'){
a[count]=1;count++;
}
else if(s[i]=='B'&&count!=0){
count--;
a[count]=3;
}
else{continue;}
}
for(int i=0;i<=count-1;i++){
printf("%d",a[i]);
}
}
|
#include <stdio.h>
#include <string.h>
int main(){
char s[10]={'\0'};
char input[10];
int now=0,i,len;
scanf("%s",input);
len=strlen(input);
for(i=0;i<len;i++){
switch((int)input[i]){
case '1':
s[now]='1';
now++;
break;
case '0':
s[now]='0';
now++;
break;
case 'B':
if(now>0){
s[now-1]='\0';
now--;
} else {
s[now]='\0';
}
}
}
printf("%s",s);
}
|
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main(void) {
#ifdef DEBUG
printf("");
#endif
char N[11];
char ans[11];
int i=0,j=0;
memset(N, '\0', 11);
memset(ans, '\0', 11);
scanf("%s", &N);
while (N[i] != '\0') {
if (N[i] == '1') {
ans[j] = '1';
}
else if (N[i] == '0') {
ans[j] = '0';
}
else {
j--;
if (j >= 0) {
ans[j] = '\0';
j--;
}
}
i++;
j++;
}
printf("%s\n",ans);
return 0;
}
|
#include <stdio.h>
#define STR_MAX 10
int main(void)
{
char str_in[STR_MAX + 1] = {'\0'};
char str_out[STR_MAX + 1] = {'\0'};
char *pOut;
int cnt;
scanf("%s", str_in);
pOut = str_out;
for (cnt = 0; ((str_in[cnt] != '\0') && (cnt < STR_MAX)); cnt++) {
if (str_in[cnt] == '0') {
*pOut = '0';
pOut++;
} else if (str_in[cnt] == '1') {
*pOut = '1';
pOut++;
} else if ((str_in[cnt] == 'B') && (pOut != &str_out[0])) {
pOut--;
*pOut = '\0';
} else {
;
}
}
printf("%s\n", str_out);
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char s[11],ans[11];
scanf("%s",s);
int len = strlen(s),i,j,left = 0;
for (i = 0; i < len; i++)
{
if(s[i] == '0')
{
ans[left] = '0';
left++;
}
else if(s[i] == '1')
{
ans[left] = '1';
left++;
}
else
{
left--;
if(left < 0)left = 0;
}
}
for (i = 0; i < left; i++)
{
printf("%c", ans[i]);
}
}
|
#include <stdio.h>
#include <string.h>
int main(void)
{
int i,j;
char s[11];
char end[1];
end[0]='\0';
scanf("%s",s);
strcat(s,end);
for(i=0;i<=9;i++)
{if(s[i]=='B'&& i != 0)
{j=i;
i-=2;
fprintf(stderr,"i!=0で%s→",s);
for(j;j<=9;j++)
{
s[j-1]=s[j+1];
s[j]='\0';
s[j+1]='\0';
}
fprintf(stderr,"%s\n",s);
}
if(s[i]=='B' && i == 0)
{j=0,i--;
fprintf(stderr,"i==0で%s→",s);
for(j;j<=8;j++)
{s[j]=s[j+1];
s[j+1]='\0';
}
fprintf(stderr,"%s\n",s);
}
}
printf("%s\n",s);
return 0;
}
|
#include <stdio.h>
//0,1,/b
//jika 0 taro di kanan
//jika 1 taro di kanan
//jika /b kalo ksoog gpp,kalo ada remove
int main(){
char s[15]; // untuk cek
scanf("%s",s);
int idx = 0; //diset array ke 0 dulu
char s2[15]; //untuk nampung array baru
for(int i=0;s[i] != '\0';i++){
if(s[i] == '0'){
s2[idx] = '0'; //tambah 0 di s2[0] nanti tmbh idx seiring loop
idx++; //kalau sudah nambah index array
}
else if (s[i] == '1'){
s2[idx] = '1';
idx++;
}
else if (s[i] == 'B'){
if(idx != 0){ //kalau indexnya tidak kosong maka
idx--; //mundur ke index sblmnya
s2[idx] = ' ';
//hapus index sblmnya
}
}
}
printf("%s",s2);
return 0;
}
|
#include <stdio.h>
int main(void){
char key[11];
char out[11];
for(int i=0;i<11;i++)
{
key[i] = out[i] = 0;
}
gets(key);
int i=0,j=0;
while(1)
{
switch(key[i])
{
case '0':
out[j] = '0';
j++;
break;
case '1':
out[j] = '1';
j++;
break;
case 'B':
if(j>0)
{
out[--j] = 0;
}
break;
default:
puts(out);
return 0;
}
i++;
}
}
|
//gcc -std=gnu11 -O2 -o a.out Main.c -lm
//http://abc043.contest.atcoder.jp/tasks/abc043_b
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdint.h>
#include <math.h>
#include <string.h>
int main(void)
{
#define N_MAX 10
int ret;
int i,j;
char strBuf[N_MAX+1];
//-------------------------------------
//Input process
//-------------------------------------
memset(strBuf, 0x00,sizeof(strBuf));
ret = scanf("%s", strBuf);
//-------------------------------------
//Calc process
//-------------------------------------
for(i=0;i<sizeof(strBuf);i++){
if(strBuf[i]==0x00){
break;
}
if(strBuf[i] == 'B'){
if(i){
memmove(&strBuf[i-1], &strBuf[i+1], (sizeof(strBuf)-i)+1 );
}else{
memmove(&strBuf[0], &strBuf[i+1], (sizeof(strBuf)-1) );
}
i=-1;
}
}
//-------------------------------------
//Output process
//-------------------------------------
printf("%s\n", strBuf);
return(0);
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define TLong long long
// abs(n)
int abs(int n){
if(n < 0) n *= -1;
return n;
}
// gcd(a,b)
int gcd(int a,int b){
int ret;
ret = (b == 0) ? a : gcd(b, a % b);
}
// lcm(a.b)
int lcm(int a,int b){
return (a * b) / gcd(a,b);
}
// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
return (*a - *b);
}
// append(array,*size,addNum)
void append(int *array,int *size,int num){
realloc(array, sizeof(int) * (*size + 1));
array[(*size)] = num;
++(*size);
}
// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
int temp = array[(*size - 1)];
realloc(array,sizeof(int) * (*size - 1));
--(*size);
return temp;
}
int main(void){
char instr[11],outstr[11]="";
scanf("%s",instr);
for(int i = 0; i < strlen(instr); ++i){
if(instr[i] == 'B') outstr[strlen(outstr) - 1] = '\0';
else outstr[strlen(outstr)] = instr[i];
}
printf("%s",outstr);
return 0;
}
|
#include <stdio.h>
int main(){
char s[10];
int i;
for(i = 0; i < 10; i++){
s[i] = getchar();
if(s[i] == '\n' || s[i] == '\r') break;
}
s[i] ='\0';
int s_index = 0;
int s_len = i;
int consec_b_count = 0;
if(s[0] == 'B'){ // if first letter is B, don't need to delete anything beforehand
while(s[s_index] == 'B'){
s_index++;
}
}
while(s_index < s_len){
s_index++;
if(s[s_index] == 'B' ){
consec_b_count++;
}
else if( consec_b_count != 0){ // if we run into a 0 or a 1 after a B
int index_to_change = s_index - consec_b_count;
for(; consec_b_count > 0; consec_b_count--){
if(index_to_change < 0){
consec_b_count = 0;
break;
}
while( s[index_to_change] !='0' && s[index_to_change] !='1' ){
index_to_change--;
if(index_to_change < 0){
break;
}
}
if(index_to_change < 0){
consec_b_count = 0;
break;
}
s[index_to_change] = 'X';
index_to_change--;
}
}
}
i = 0;
while(i < s_len){
if(s[i] == '0' || s[i] == '1') printf("%c", s[i]);
i++;
}
return 0;
}
|
/* ex9_1
L40S38 */
#include<stdio.h>
#include<stdlib.h>
typedef struct stack{
char row[11];
//入力される文字列は最大10文字+ヌル文字
int letter_num;
//文字列の長さ
}stack;
void push(stack *stack_p,char *letter){
//stackの文字列の最後にletterを加える
stack_p->row[stack_p->letter_num]=*letter;
stack_p->letter_num++;
return;
}
void pop(stack *stack_p){
//stackの文字列の最後の文字を削除
if(stack_p->letter_num!=0){
stack_p->letter_num--;
stack_p->row[stack_p->letter_num]='\0';
}
return;
}
int main(void){
stack *Stack;
Stack=(stack*)calloc(1,sizeof(stack));
if(Stack==NULL){
printf("ERROR");
return -1;
}
char input[11];
//input:入力された'0','1','B'のみでできた文字列
int i=0;
//入力された文字列をinputに格納
scanf("%s",input);
//input[i]ごとにStack中の文字列における処理を変更
while(input[i]){
if(input[i]=='B'){
//バックスペースキーの時はpop操作
pop(Stack);
}
else{
//それ以外の時はpush操作
push(Stack,&input[i]);
}
i++;
}
//結果の出力
for(i=0;i<Stack->letter_num;i++){
printf("%c",Stack->row[i]);
}
putchar('\n');
free(Stack);
return 0;
}
|
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;
const double PI = 3.1415926535897932384626433;
const int MOD = 1e9+7;
const int INF = 1e9;
#define rep(i, n) for(int i=0;i<(n);++i)
#define SIZE 20
//prototype declaration
//gloval variable
typedef struct{
int size;
int count;
char data[SIZE];
char * top;
}stack;
void initialize(stack * s){
s->size = SIZE;
s->count = 0;
s->top = &(s->data[SIZE]);
}
void push(stack * s, char x){
if(s->count >= s->size){
fprintf(stderr, "Error: stack overflow.\n");
exit(1);
}else{
s->top--;
*(s->top) = x;
s->count++;
}
}
int pop(stack * s){
int x;
if(s->count <= 0){
return 0;
}else{
x = *(s->top);
s->top++;
s->count--;
return x;
}
}
void print_all(stack * s){
char * p = (s->top)+(s->count-1);
for(int i = 0; i < s->count; i++, p--){
printf("%c", *p);
}
printf("\n");
}
int main(void){
char s[10];
scanf("%s", s);
stack stack;
initialize(&stack);
for(int i = 0; s[i]!='\0'; i++){
if(s[i] != 'B'){
push(&stack, s[i]);
}else{
pop(&stack);
}
}
print_all(&stack);
return 0;
}
|
/* ex9_1 Stack (Keyboard)
pandacodeb */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 10
typedef struct stack{
int size;
int count;
char data[SIZE];
char *top;
}stack;
void init_stack(stack *stk){
stk->count = 0;
stk->size = SIZE;
stk->top = &(stk->data[SIZE]);
}
void push(stack *stk, char key){
if (stk->count >= stk->size)
exit(1);
else{
stk->top--;
*(stk->top) = key;
stk->count++;
}
}
char pop(stack *stk){
char latest;
if (stk->count <= 0){
return ' ';
}
else{
latest = *(stk->top);
stk->top++;
stk->count--;
return latest;
}
}
void print_s(stack *stk){
char *ptr;
ptr = (stk->top)+(stk->count)-1;
for (int i = 0; i < stk->count; i++)
printf("%c", *ptr--);
printf("\n");
}
int main(void){
int i;
char del;
char* text;
text = (char*) malloc(sizeof(char)*10);
scanf("%s", text);
stack stk;
init_stack(&stk);
for (i = 0; i < strlen(text); i++){
if (text[i] == '0' || text[i] == '1')
push(&stk, text[i]);
else if (text[i] == 'B')
del = pop(&stk);
}
print_s(&stk);
return 0;
}
|
/*ex9_1 hightierra*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 1000
// スタックの定義
typedef struct{
int size;
int count;
char data[SIZE];
char *top;
}stack;
// 初期化
void initialize(stack *stk){
stk->count = 0;
stk->size = SIZE;
stk->top = &(stk->data[0]);
}
// pushとpopの定義
void push(stack *stk, char pushdata){
if(stk->count >= stk->size){
printf("Error: Stack overflow.");
exit(1);
}else{
*(stk->top) = pushdata;
stk->top++;
stk->count++;
}
}
char pop(stack *stk){
char popdata;
if(stk->count <= 0){
printf("Error: Stack underflow.");
exit(1);
}else{
popdata = *(stk->top);
stk->top--;
stk->count--;
return popdata;
}
}
int main(void){
stack input;
char key[SIZE],popdata;
int i;
initialize(&input);
// 入力データをkeyにいれる
scanf("%s",key);
// 入力データ分ループし、popかpush
for(i=0; i<strlen(key); i++){
if(key[i] != 'B'){
push(&input,key[i]);
}else if(key[i] == 'B' && (input.count)>0){
popdata = pop(&input);
}
}
for(i=0; i<input.count; i++){
printf("%c",input.data[i]);
}
printf("\n");
return 0;
}
|
#include<stdio.h>
#include<stdlib.h>
#define datatype char
#define max 10
struct stack{
int maxsize;
int top;
datatype item[max];
};
struct stack* init_stack(struct stack *p){
p = (struct stack *)malloc(sizeof(struct stack));
p->top = -1;
p->maxsize = max;
return p;
}
void push(struct stack *p, datatype a){
p->top++;
if(p->top >= p->maxsize){
printf("overflow\n");
exit(1);
}else{
p->item[p->top] = a;
}
}
datatype pop(struct stack *p){
if(p->top > -1){
datatype a;
a = p->item[p->top];
p->top--;
return a;
}else{
printf("underflow\n");
exit(1);
}
}
int empty_stack(struct stack *p){
/*if stack is empty, return 1. Else, return 0.*/
return p->top == -1;
}
void print_stack(struct stack *p){
while(p->top != -1){
printf("%c", pop(p));
}
printf("\n");
}
void print_stack_r(struct stack *p){
struct stack *a;
a = init_stack(a);
while(empty_stack(p) == 0){
push(a, pop(p));
}
print_stack(a);
}
int main(){
int i, tmp, m;
tmp = 0;
datatype buf[11], s[11];
for(i = 0; i < 11; i++)s[i] = '\0';
struct stack *a;
a = init_stack(a);
scanf("%s", buf);
for(i = 0; buf[i] != '\0'; i++){
if(buf[i] == 'B' && empty_stack(a)){
}else if(buf[i] == 'B'){
pop(a);
}else{
push(a, buf[i]);
}
}
print_stack_r(a);
return 0;
}
|
/*
ex9_1
takaoga
*/
#include<stdio.h>
#include<stdlib.h>
#define SIZE 10
typedef struct{
int size;
int count;
char data[SIZE];
char *top;
char *bottom;
} stack;
void initialize_text(stack *text){
text->count = 0;
text->size = SIZE;
text->top = &(text->data[SIZE]);//topはpushやpopをする毎に変動する。
text->bottom = &(text->data[SIZE]);//data[10]を底と見なす。これは動かない。
}
void push(stack *text, char textcharacter){
*(text->top) = textcharacter;
text->top--;
text->count++;
}
void pop(stack *text){
text->top++;
text->count--;
}
void print_text(stack *text){
char *textbottom;
textbottom = text->bottom;
for(int i = 0 ; i < text->count ; i++){
printf("%c", *textbottom--);//botomから遡って出力することで、最初に入力した文字の順番で出力される
}
printf("\n");
}
stack text;
int main(void){
char inputtext[10],*nowtext;
initialize_text(&text);//初期化
scanf("%s",inputtext);
nowtext = &(inputtext[0]);
while(*nowtext != '\0'){
if(*nowtext == '0' || *nowtext == '1'){
push(&text, *nowtext);//もし現在のもじが1か0であればpush
}else if(*nowtext == 'B'){
if(text.top != text.bottom){
pop(&text);//もし現在の文字がBでありかつ文字列が空でなければpop
}
}
nowtext++;
}
print_text(&text);
return 0;
}
|
/* ex9_1
fmuacshai */
# include<stdio.h>
#include<stdlib.h>
#include<string.h>
# define SIZE 20
//スタックの定義
typedef struct{
int size;
int count;
char string[SIZE];
char *top;
} stack;
//データの追加
void push(stack *stk,char character){
if(stk->count>=stk->size){
exit(1);
}else{
stk->top--;
*(stk->top)=character;
stk->count++;
}
}
//データの取り出し
char pop(stack *stk){
char latest;
if(stk->count<=0){
exit(1);
}else{
latest=*(stk->top);
stk->top++;
stk->count--;
return latest;
}
}
//データの初期化
void initialize(stack *stk){
stk->size=SIZE;
stk->count=0;
stk->top=&(stk->string[SIZE]);
}
//データの出力
void output(stack *stk){
int i;
for(i=0;i<stk->count;i++){
printf("%c",stk->string[SIZE-i-1]);
}
printf("\n");
}
int main(void){
int i;
//stack stkの定義
stack stk;
//入力で利用するinputを定義
char input[SIZE];
//データを初期化
initialize(&stk);
//入力
scanf("%s",input);
//追加と消去をする
for(i=0;i<strlen(input);i++){
// 0 or 1ならスタックに保存
if(input[i]=='0'||input[i]=='1'){
push(&stk, input[i]);
//Bならスタックから一つ取り出す。(取り出すものがある場合)
}else if(input[i]=='B'&&stk.count>0){
pop(&stk);
}
}
//出力
output(&stk);
return 0;
}
|
/* ex 9_1
series2 */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
//条件 文字列を格納するスタックを定義、push,pop
typedef struct stack {
int size;
int count; //現在格納されている文字数
char data[SIZE]; //データ内容そのもの
char *top; //外部からのアクセス部はdata配列の一番後ろの番地のアドレスをさす
} stack;
void init_stack(stack *stk) {
stk->count = 0;
stk->size = SIZE;
stk->top = &(stk->data[SIZE]);
}
void push(stack *stk, char data) {
if (stk->count <
stk->size) { //用意したstackの要領未満の時、入力文字をトップアドレスに追加する
stk->top--;
*(stk->top) = data;
stk->count++;
}
}
char pop(stack *stk) {
char latest;
if (stk->count > 0) { //文字が残っている時
latest = *(stk->top);
stk->top++;
stk->count--;
return latest;
} else {
latest = '\0'; //文字が残っていない時null文字を返す
}
return latest;
}
// stackなので、再帰的に呼び出すことで正しい順にする。(直接呼び出すのは、stackとしての設計に反する)
void printout(stack *stk) {
char out = pop(stk);
if (out) { // outがnull文字でない時
printout(stk);
printf("%c", out);
}
}
int main(void) {
stack stk;
init_stack(&stk);
char inp = ' ';
while (inp != '\n') {
scanf("%c", &inp);
if (inp == 'B') {
pop(&stk);
} else if (inp != '\n') {
push(&stk, inp);
}
}
printout(&stk);
printf("\n");
return 0;
}
|
/*
ex 9_1
tomatokan
*/
#include <stdio.h>
#include<stdlib.h>
#define LIM 12
typedef struct stack{//スタック
int count;
int msg[LIM];
int *top;
}stack;
stack new_stack(){//初期化されたスタック(空)を返す。
stack st;
st.count=0;
for(int i=0;i<LIM;i++){
st.msg[i]=0;
}
st.top=st.msg;
return st;
}
void push_stack(stack *st, int elem){
if(st->count>=LIM){
fprintf(stderr,"stack overflow");
exit(1);
}
(st->count)++;
st->msg[st->count-1]=elem;
(st->top)++;
}
int pop_stack(stack *st){
if(st->count<=0){
fprintf(stderr,"stack underflow");
exit(1);
}
(st->count)--;
(st->top)--;
return *(st->top);
}
void print_stack(stack *st){
for(int i=0;i<st->count;i++){
printf("%d",st->msg[i]);
}
printf("\n");
}
int is_empty(stack *st){
if(st->count==0){
return 1;
}
return 0;
}
int main(void){
char input[12];
char *ptr;
stack st;
ptr=input;
fgets(input,12,stdin);//入力の読み取り
st=new_stack();
while(*ptr!='\0'&&*ptr!='\n'){
if(*ptr=='0'){
push_stack(&st,0);
}else if(*ptr=='1'){
push_stack(&st,1);
}else{
if(!is_empty(&st)){
pop_stack(&st);
}
}
ptr++;
}
print_stack(&st);//結果の表示
return 0;
}
|
//ex9_1
//TKC001
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 10
//data[SIZE-1]がstackの底、data[0]が天井、topはstackの一番上の要素の位置
typedef struct stack{
int size;
int count;
char data[SIZE];
char *top;
} stack;
//stackの初期化、何もないっていない状態にする。
void init_stack(stack *stk){
stk->count = 0;
stk->size = SIZE;
stk->top = &(stk->data[SIZE]);
}
//番号が若い方が上なので、stackに要素が追加されるとtopが小さくなる
void push(stack *stk, char elem){
if(stk->count >= stk->size){
fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
exit(1);
}
else{
stk->top--;
*(stk->top) = elem;
stk->count++;
}
}
//配列dataの一番番号の若いやつをstackから外す。
void delete(stack *stk){
if(stk->count <= 0){
//何もしないけど気持ち悪いから書いた
}
else{
stk->top++;
stk->count--;
}
}
//dataの中身を後ろからcount個出力=stackの内容をすべて出力
void print_stack(stack *stk){
int i;
for(i = SIZE-1; i > SIZE-1-stk->count; i--){
printf("%c", stk->data[i]);
}
}
int main(void){
int i;
char str[SIZE+1];
stack stk;
//stackの初期化
init_stack(&stk);
//入力
scanf("%s", str);
//strの要素に応じてpushとdeleteを決める
for (i = 0; i < strlen(str); i++){
if(str[i] == 'B'){
delete(&stk);
}
else if(str[i] == '0'){
push(&stk, '0');
}else{
push(&stk, '1');
}
}
//出力
print_stack(&stk);
return 0;
}
|
/* ex 9_1
KitamoriFumiya */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 11
// stack型(格納最大数、データ数、データ配列、topへのポインタ)を定義
typedef struct stack{
int size;
int count;
char data[SIZE];
char *top;
} stack;
void initialize_stack(stack *stk);
void print_stack(stack *stk);
void push(stack *stk, char letter);
char pop(stack *stk);
// 文字列を格納するスタックを用意
stack stk;
int main(void){
char input[11], *ptr_input; // キーボードでの入力を格納するための配列とポインタ
initialize_stack(&stk); // スタックを初期化
scanf("%s", input); // 文字列の入力
ptr_input = input;
while(*ptr_input){
// 文字がBであり、その前の文字があればそれを消す
if(*ptr_input == 'B'){
if(stk.count>0){
pop(&stk);
}
}else{
push(&stk, *ptr_input);
}
++ptr_input;
}
// 出力
print_stack(&stk);
}
// スタックの初期化
void initialize_stack(stack *stk){
stk->count = 0;
stk->size = SIZE;
stk->top = &(stk->data[SIZE]);
}
// データを追加する
void push(stack *stk, char leter){
if(stk->count >= stk->size){
printf("Error: stack overflow. (leter=%c)\n", leter);
exit(1);
}else{
stk->top--;
*(stk->top) = leter;
stk->count++;
}
}
// データを取り出す
char pop(stack *stk){
char now;
if(stk->count <= 0){
printf("Error: stack underflow.\n");
exit(1);
}else{
now = *(stk->top);
stk->top++;
stk->count--;
return now;
}
}
// スタックの中身を逆順に取り出す
void print_stack(stack *stk){
char output[11], *ptr_output;
int i;
ptr_output = stk->top;
for(i = stk->count; i > 0; i--){
output[i-1] = *ptr_output;
ptr_output++;
}
printf("%s\n", output);
}
|
/* ex9_1
kt125*/
#include<stdio.h>
#include<stdlib.h>
#define SIZE 11
typedef struct{
int size; //格納最大数
int count; //データ数
char data[SIZE]; //データの配列
char *top; //topへのポインタ
} stack;
void initialize_stack(stack *stk); //スタックを初期化する関数
void print_stack(stack *stk); //スタックの中身をprintする関数
void push(stack *stk, char x); //スタックのpush操作をする関数
void pop(stack *stk); //スタックのpop操作wpする関数
stack stk;
int main(void){
char key[12];
char *ptr;
scanf("%s", key); //入力を読み取る
ptr = key; //keyの先頭アドレスを渡す
initialize_stack(&stk);
while(*ptr){ //ヌル文字に至るまで数字ならpush,'B'ならpop
if( *ptr == '0' || *ptr == '1'){
push(&stk, *ptr);
}else{
pop(&stk);
}
ptr++;
}
print_stack(&stk);
return 0;
}
void initialize_stack(stack *stk){
stk->count = 0;
stk->size = SIZE;
stk->top = &(stk->data[SIZE]); //データの一番後ろのアドレスを渡す
}
void pop(stack *stk){
if(stk->count <= 0){ //データが空のときは何もしない
return;
}else{
stk->top++;
stk->count--;
}
}
void push(stack *stk, char x){
if(stk->count >= stk->size){ //エラー出力
printf("Error:stack overflow. (x=%lf)\n", x);
exit(1);
}else{
//topをずらして、そのアドレスに新たにxを追加
stk->top--;
*(stk->top) = x;
stk->count++;
}
}
void print_stack(stack *stk){
char *p;
p = &(stk->data[SIZE-1]);
//stkには古いものが後ろに格納されているので後ろからprint
for(int i=0; i<stk->count; i++){
printf("%c", *p--);
}
printf("\n");
}
|
/* ex9_1
shu_t */
#include <stdio.h>
#include <stdlib.h>
//1<=|s|<=10 + '\0'
#define SIZE 11
typedef struct stack{
int size;//max size of stack
int count;//the number of data
char data[SIZE];//data array
char *top;//pointer of top
}stack;
void initialize_stack(stack *stk){//initialization
stk->count=0;
stk->size = SIZE;
stk->top=&(stk->data[SIZE]);//top is final element
}
void push(stack *stk,char elem){
if(stk->count < stk->size){//prevent overflow
stk->top--;//push top
*(stk->top)=elem;//store data
stk->count++;//increment
}
}
void pop(stack *stk){
if(stk->count > 0){//prevent underflow
stk->top++;//pop top
stk->count--;//decrement
}
}
void print_stack(stack *stk){
char *ptr;
int i;
ptr = stk->top;//to top pointer
while(i<stk->count-1){//move to old data
ptr++;
i++;
}
for(i=0;i<stk->count;i++){//from old data to new data
printf("%c",*ptr--);
}
printf("\n");//make a new line
}
int main(void){
stack string;
int i;//roop variable
char keyboard[SIZE];//for input
//input string
scanf("%s",keyboard);
//initialize stack
initialize_stack(&string);
//stack
for(i=0;i<SIZE;i++){
if(keyboard[i] == '0'){
push(&string,'0');
}
else if(keyboard[i] == '1'){
push(&string,'1');
}
else if(keyboard[i]=='B'){
pop(&string);
}
}
//output
print_stack(&string);
return 0;
}
|
/* ex9_1:
Jun_JPN*/
#include <stdio.h>
#include <stdlib.h>
#define SIZE 128
typedef struct{
int size; // 格納際代数
int count; // 現在のデータ数
char str[SIZE]; // 文字列
char *top; // トップへのポインタ(トップは末尾の要素の1つ上の要素のポインタ)
}stack;
void initialize_stack(stack *stk);
void print_stack(stack *stk);
void push(stack *stk, char bin);
void pop(stack *stk);
int main(void){
stack stk;
char str[SIZE];
int i;
scanf("%s", str); // 文字列を受け取る
initialize_stack(&stk); // スタックstkを初期化
for(i=0; str[i] != '\0'; i++){
if(str[i]=='B') pop(&stk); // Bが来たらポップ
else push(&stk, str[i]); // B以外が来たらプッシュ
}
print_stack(&stk);
return 0;
}
/* スタックを初期化 */
void initialize_stack(stack *stk){
stk->count = 0;
stk->size = SIZE;
stk->str[0] = '\0';
stk->top = &(stk->str[0]); // 頭文字のポインタををtopに
}
/* スタックの中身を表示 */
void print_stack(stack *stk){
for(int i=0; stk->str[i] != '\0'; i++){
printf("%c", stk->str[i]);
}
printf("\n");
}
/* B以外の文字ををプッシュ */
void push(stack *stk, char bin){
if(stk->count >= stk->size){ // オーバーフロー処理
printf("Error: stack overflow\n");
exit(1);
}else{
*(stk->top) = bin; // スタックのトップに文字を加える
stk->top++; // スタックのトップを1つ上に
*(stk->top) = '\0'; // スタックのトップをヌル文字に
stk->count++;
}
}
/* Bが来たらポップ
要素を取り除く=要素をヌル文字で書き換える */
void pop(stack *stk){
if(stk->count <= 0){ // アンダーフロー処理
; // 何もしない
}else{
stk->top--; // スタックのトップを1つ下に
*(stk->top) = '\0'; // スタックのトップをヌル文字に
stk->count--;
}
}
|
/* ex9_1
Y_Aizaki */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 20
typedef struct string
{
int size;
int count;
char date[SIZE];
char *top;
}string;
void initialize_string(string *str); // stringの初期化
void print_string_queue(string *str); // 先頭から取り出す
void push(string *str, char unit); // stringへの追加
char pop(string *str); // stringからの削除・取り出し
int main(void){
string str;
string *str_p = &str;
char input[SIZE+1];
// 標準入力を受け取る
char *point = input;
// inputからstrへ移す際のポインター
char garbage;
// popで取り出されるcharを捨てる場所
scanf("%[01B]", input);
initialize_string(str_p);
// strの初期化
while (*point){
// Bだったらpop
if (*point == 'B'){
if (str_p->count != 0)
{
garbage = pop(str_p);
}
}
// 0か1だったらpush
else{
push(str_p, *point);
}
point++;
}
print_string_queue(str_p);
return 0;
}
void initialize_string(string *str){
str->count = 0;
str->size = SIZE;
str->top = &(str->date[SIZE]);
}
void print_string_queue(string *str){
char *point;
point = &(str->date[SIZE-1]);
for (int i = 0; i < str->count; i++){
printf("%c", *point--);
}
putchar('\n');
}
void push(string *str, char unit){
if (str->count >= str->size){
printf("Error stack overflow. (unit=%c)\n", unit);
exit(1);
}
else{
str->top--;
*(str->top) = unit;
str->count++;
}
}
char pop(string *str){
char latest = '\0';
if (str->count <= 0){
printf("Error stack underflow.\n");
}
else{
latest = *(str->top);
str->top++;
str->count--;
}
return latest;
}
|
/* ex9_1
suuxxu */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
typedef struct { // 文字列を格納するスタック
int size; // 最大データ数
int count; // 現在のデータ数
char data[SIZE]; // データ配列
char *top; // topへのポインタ
} stack;
void initialize_stack(stack *stk); // スタックの初期化
void print_stack(stack *stk); // スタックの中身を古い順に出力
void push(stack *stk, char chr); // スタックのpush操作
char pop(stack *stk); // スタックのpop操作
stack stk;
int main(void){
int i;
char input[10], tmp;
initialize_stack(&stk); // スタックを初期化
scanf("%s", input); // 入力をinputに格納
for(i = 0; i < strlen(input); i++){
if(input[i] == 'B'){ // バックスペースなら
tmp = pop(&stk); // popで1番新しい要素を削除
}else{
push(&stk, input[i]); // それ以外の文字ならpushで要素を追加
}
}
print_stack(&stk); // 結果を出力
return 0;
}
void initialize_stack(stack *stk){ // スタックの初期化
stk->count = 0; // 現在のデータ数を0に
stk->size = SIZE; // 最大データ数をSIZEに
stk->top = &(stk->data[SIZE]); // topを配列の最終要素の1つ手前に
}
void push(stack *stk, char chr){ // スタックのpush操作
if(stk->count >= stk->size){
printf("Error: stack overflow. (x=%c)\n", chr); // 容量がオーバーフローする
exit(1);
}else{
stk->top--; // topを1つ手前に移動
*(stk->top) = chr; // topにデータを格納
stk->count++; // データ数を1つ増やす
}
}
char pop(stack *stk){ // スタックのpop操作
char chr;
if(stk->count > 0){
chr = *(stk->top); // topの位置のデータを取り出す
stk->top++; // topを1つ後ろに移動
stk->count--; // データ数を1つ減らす
return chr;
}
}
void print_stack(stack *stk){ // スタックの中身を古い順に出力
int i, len;
char output[10];
len = stk->count; // 出力の長さを記録
for(i = 1; i <= len; i++){
output[len - i] = pop(stk); // スタックからpopしたデータを後ろからoutputに記録
}
for(i = 0; i < len; i++){
printf("%c", output[i]); // outputを出力
}
printf("\n");
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.