label
stringlengths 1
2
| index
stringlengths 1
5
| code
stringlengths 87
8.24k
|
---|---|---|
17 | 8300 | int main()
{
char a[500],b[500]={0};
int n,i,k,j,jud[500]={0},max=0;
for(i=0;i<500;i++)
{
a[i]=0;jud[i]=0;
}
while(scanf("%s",a)!=EOF)
{
for(i=0;i<500;i++)
{
b[i]=0;
}
for(i=0;i<strlen(a);i++)
{
b[i]=' ';
}
for(i=0;i<strlen(a);i++)
{
if(a[i]==')')
{
for(j=i-1;j>=0;j--)
{
if(a[j]=='('&&jud[j]==0)
{
jud[j]=1;
jud[i]=1;
break;
}
}
}
}
for(i=0;i<strlen(a);i++)
{
if(a[i]=='('&&jud[i]==0)
{
b[i]='$';
}
if(a[i]==')'&&jud[i]==0)
{
b[i]='?';
}
}
printf("%s\n%s\n",a,b);
for(i=0;i<500;i++)
{
a[i]=0;jud[i]=0;
}
}
} |
17 | 8301 | int len;
char str[101];
void f ( int p ) {
int m = -1 , n = -1;
for ( int i = p; i >= 0; i -- ) {
if (*( str + i ) == '(') {
m = i;
break;
}
}
for ( int i = m + 1; i <= len - 1; i ++ ) {
if (*( str + i ) == ')') {
n = i;
break;
}
}
if ( m >= 0 && n >= 0 ) {
str[m] = '#';
str[n] = '#';
}
if ( m > 0 ) {
f ( m - 1 );
}
}
int main() {
while( cin >> str ) {
len = strlen( str );
cout << str << endl;
f ( len );
for ( int j = 0;j <= len - 1; j ++ ) {
if ( str[j] == '(' ) cout << "$";
else if ( str[j] == ')' ) cout << "?";
else cout << " ";
}
cout << endl;
}
return 0;
}
|
17 | 8302 | int main()
{
char str[101]={"0"};
int i,j,len,zuo,you,a[100];
while(scanf("%s",str)!=EOF){
len=strlen(str);
for(i=0;i<len;i++)
a[i]=0;
for(i=len-1;i>=0;i--){
if(str[i]=='('){
zuo=0;you=0;
for(j=i+1;j<len;j++){
if(str[j]=='('&&a[j]!=1)
zuo++;
else if(str[j]==')')
you++;
}
if(you<zuo+1)
a[i]=1;
}
}
for(i=0;i<len;i++){
if(str[i]==')'){
zuo=0;you=0;
for(j=0;j<i;j++){
if(str[j]=='(')
zuo++;
else if(str[j]==')'&&a[j]!=-1)
you++;
}
if(zuo<you+1)
a[i]=-1;
}
}
printf("%s\n",str);
for(i=0;i<len;i++){
if(a[i]==0) printf(" ");
else if(a[i]==1) printf("$");
else printf("?");
}
printf("\n");
}
return 0;
}
|
17 | 8303 | char a[100];int b;
void nihao()
{
for(int i=0;i<b;i++)
{
int r=0;
if(a[i]==')')
{
for(int j=i-1;j>=0;j--)
{
if(a[j]=='(')
{
for(int k=j;k<=i;k++)
a[k]=' ';
r=1;
break;
}
}
if(r==0)
{
a[i]='?';
for(int k=i-1;k>=0;k--)
if(a[k]!='?')
a[k]=' ';
}
}
}
}
void nimei()
{
for(int i=b-1;i>=0;i--)
if(a[i]=='(')
{
a[i]='$';
}
}
void nima()
{
for(int i=0;i<b;i++)
{
if(a[i]!='?'&&a[i]!='$')
a[i]=' ';
}
for(int i=0;i<b;i++)
cout<<a[i];
cout<<endl;
}
int main()
{
while(cin>>a)
{
cout<<a;
cout<<endl;
b=strlen(a);
nihao();
nimei();
nima();
}
return 0;
}
|
17 | 8304 | int main()
{
char ch[110],temp[110],c[110];
int i,figure;
while(gets(ch)){
figure = 0;
for(i=0;ch[i] != '\0';i ++)
{ temp[i]=' ';
switch(ch[i]){
case '(':c[figure ++]=i;temp[i]='$';break;
case ')':if(figure){figure--;temp[c[figure]]=' ';
}
else temp[i] = '?';break;}
}
temp[i]='\0';
printf("%s\n%s\n",ch,temp);
}
return 0;
} |
17 | 8305 | main()
{
char a[101],b[101],c[101];
while(gets(a)!=NULL)
{int i=0,j=0,k=0;int n;
n=strlen(a);
for(i=0;i<n;i++)
{b[i]=' ';
c[i]=' ';}
for(i=n-1;i>=0;i--)
if(a[i]=='(')
b[i]=a[i];
for(i=0;i<n;i++)
if(a[i]==')')
c[i]=a[i];
for(i=n-1;i>=0;i--)
if(b[i]=='(')
{for(j=i+1;j<n;j++)
if(c[j]==')')
{c[j]=' ';
b[i]=' ';
break;}}
printf("%s\n",a);
for(i=0;i<n;i++)
{if(b[i]!=' ')
a[i]='$';
if(c[i]!=' ')
a[i]='?';
if(b[i]==' '&&c[i]==' ')
a[i]=' ';
}
printf("%s\n",a);
}
}
|
17 | 8306 | int main()
{
char str[1000];
int l, i, j, d;
while(1)
{
gets(str);
if(str[0] == '\0')
break;
puts(str);
l = strlen(str);
for(i = 0; i < l; i++)
{
if(str[i] == ' ') continue;
if(str[i] != '(' && str[i] != ')')
str[i] = ' ';
else if(str[i] == '(')
{
d = 1;
for(j = i + 1; j < l; j++)
{
if(str[j] == '(') d++;
if(str[j] == ')') d--;
if(d == 0)
{
str[i] = ' ';
str[j] = ' ';
break;
}
}
}
}
for(i = 0; i < l; i++)
if(str[i] == '(')
printf("$");
else if(str[i] == ')')
printf("?");
else
printf("%c", str[i]);
printf("\n");
for(i = 0; i < l; i++)
str[i] = '\0';
}
return 0;
}
|
17 | 8307 |
int main()
{
char a[110];
char b[110];
char c[110];
while(gets(a))
{
strcpy(b,a);
strcpy(c,a);
int i,j;
int n=strlen(a);
int ju=0;
for(i=n-1;i>=0;i--)
{
if(a[i]=='(')
{
for(j=i;j<n;j++)
{
if(a[j]==')')
{
a[j]=99;
b[i]=b[j]=32;
break;
}
}
if(j==n)
{
b[i]='$';
}
}
}
for(i=0;i<n;i++)
{
if(b[i]!=32&&b[i]!=')'&&b[i]!='$')
b[i]=32;
else if(b[i]==')')
b[i]='?';
}
printf("%s\n",c);
printf("%s\n",b);
}
return 0;
}
|
17 | 8308 |
int main(int argc, char* argv[])
{
int N;cin>>N;
for(int I=0;I<N;I++)
{
int i;
char in[110];cin>>in;
cout<<in<<endl;
int n=strlen(in);
char mark[110]; for(i=0;i<n;i++) mark[i]=' ';
int left=0;
for(i=0;i<n;i++)
{
if(in[i]=='(') left++;
else if(in[i]==')')
{
if(left)
{left--;}
else
{
mark[i]='?';
}
}
}
int right=0;
for(i=n-1;i>=0;i--)
{
if(in[i]==')') right++;
else if(in[i]=='(')
{
if(right)
{right--;}
else
{
mark[i]='$';
}
}
}
for(i=0;i<n;i++) cout<<mark[i];
cout<<endl;
}
return 0;
}
|
17 | 8309 |
int main()
{ int i,j,t1,t2,flag,len;
int b[101],l[101],r[101];
char s[101];
while(scanf("%s",s)!=EOF){
len=strlen(s);
for(i=0;i<len;i++){
if(s[i]=='('){
b[i]=-1;
}
else if(s[i]==')'){
b[i]=1;
}
else{
b[i]=0;
}
}
t1=0;
t2=0;
for(i=0;i<len;i++){
if(b[i]==-1){
l[t1]=i;
t1++;
}
if(b[i]==1){
r[t2]=i;
t2++;
}
}
for(i=t1-1;i>=0;i--){
for(j=0;j<t2;j++){
if(r[j]>l[i]){
b[r[j]]=0;
b[l[i]]=0;
r[j]=0;
l[i]=0;
break;
}
}
}
puts(s);
for(i=0;i<len;i++){
if(b[i]==-1){
printf("$");
}
else if(b[i]==1){
printf("?");
}
else{
printf(" ");
}
}
printf("\n");
}
return 0;
}
|
17 | 8310 |
int main()
{
int left=0,right=0;
int times=0,i;
char s[101];
char c[101];
char fakes[101];
for (times=0; times==0;i=0,left=0,right=0) {
scanf("%s",s);
if (strcmp(fakes, s)==0&&strlen(fakes)==strlen(s)) {
break;
}
for (i=0; s[i]!='\0'; i++) {
if (s[i]=='(') {
left++;
}
if (s[i]==')'&&left>0) {
left--;
}
else
if (s[i]==')'&&left==0) {
c[i]='?';
}
}
for (; i>=0; i--) {
if (s[i]==')') {
right++;
}
if (s[i]=='('&&right>0) {
right--;
}
else
if (s[i]=='('&&right==0) {
c[i]='$';
}
}
puts(s);
printf("\n");
for (i=0; s[i]!='\0'; i++) {
if (c[i]=='?'||c[i]=='$') {
printf("%c",c[i]);
c[i]=0;
}
else
printf(" ");
}
printf("\n");
strcpy(fakes,s);
}
return 0;
}
|
17 | 8311 | int main()
{
typedef struct _Parenthesis
{
char ch;
int idx;
} Parenthesis;
Parenthesis paren[100];
char str[101];
while(gets(str))
{
int i,top=0;
puts(str);
for(i=0; str[i]; i++)
{
if(str[i] == '(')
{
paren[top].ch = '(';
paren[top].idx = i;
top++;
}
else if(str[i] == ')')
{
if(top == 0)
str[i] = '?';
else
{
str[i] = ' ';
str[paren[--top].idx] = ' ';
}
}
else
str[i] = ' ';
}
for(i=0; i<top; i++)
str[paren[i].idx] = '$';
puts(str);
}
return 0;
} |
17 | 8312 | int main()
{
int n,k,i,j,flag=0;
char s[M]={""};
scanf("%s",s);
while((s[0]>='a'&&s[0]<='z')||(s[0]>='A'&&s[0]<='Z')||s[0]=='('||s[0]==')')
{
printf("%s\n",s);
n=strlen(s);
for(i=n-1;i>=0;i--)
{
if(s[i]=='(')
{
for(j=i+1;j<n;j++)
{
if(s[j]==')')
{
s[i]='a';
s[j]='a';
break;
}
}
}
}
for(i=0;i<n;i++)
{
if(s[i]=='('||s[i]==')')
{
flag=1;
break;
}
}
if(flag==0)
{
for(i=0;i<n;i++)
printf("%c",' ');
printf("\n");
}
else
{
for(i=0;i<n;i++)
{
if(s[i]=='(')
printf("%c",'$');
else if(s[i]==')')
printf("%c",'?');
else
printf("%c",' ');
}
printf("\n");
}
s[0]='\0';
scanf("%s",s);
}
return 0;
}
|
17 | 8313 | int brackets(void){
int chart[2][100],c,count=0,pos,state = 0,tmp,first_left,previous_left,end_flag = 0;
/*state:0 for search left(start,you have to move right)
1 for have left and search right(you have to move right)
2 for search previous left(you have to move left)
*/
for(;;count++){
c = getchar();
if(c == EOF)return 1;
if(c == '\n'){break;}
chart[0][count] = c;
if(c == 40){chart[1][count] = 36;} //$
else if(c == 41){chart[1][count] = 63;} //?
else{chart[1][count] = 32;} //
}
for(pos=0;end_flag == 0;){
switch(state){
case 0:
if(chart[1][pos] == 36){
state = 1; //switch to state 1
first_left = pos; //note the current first left bracket
previous_left = pos; //note the previous left bracket
if(pos == count){end_flag = 1;}
else{pos += 1;} //move right
}
else{
if(pos == count){end_flag = 1;} //end of loop
else{pos += 1;}//move right
}
break;
case 1:
if(chart[1][pos] == 63){
chart[1][pos] = 32; //match
chart[1][previous_left] = 32;
if(previous_left != first_left){
state = 2; //switch to state 2
pos = previous_left; //jump to previous left
}
else{
if(pos == count){end_flag = 1;}
else{
state = 0;
pos += 1;
}
}
}
else if(chart[1][pos] == 36){
previous_left = pos; // renew previous left bracket
pos += 1; //move right
}
else{
if(pos == count){end_flag = 1;}
else{pos += 1;} //find a space,move right
}
break;
case 2:
if(chart[1][pos] == 36){
previous_left = pos;
state = 1;
}
else{pos -= 1;}
break;
}
if(pos > count){pos = count;}//force position
}
for(tmp=0;tmp < count;tmp++){
putchar(chart[0][tmp]);
if(tmp == count - 1){putchar('\n');}
}
for(tmp=0;tmp < count;tmp++){
putchar(chart[1][tmp]);
if(tmp == count - 1){putchar('\n');}
}
return 0;
}
int main(){
while(1){
if(brackets() == 1)break;
}
return 0;
} |
17 | 8314 | char A[100],a[100];
int i,j=0,m;
int k;
int main()
{
void pipei1(char x);
void pipei2(char x);
int n;
while(gets(a))
{
i=0;
m=0;
k=strlen(a);
if(k==0)
break;
for(n=0;n<k;n++)
{
A[n]=' ';
cout<<a[n];
}
pipei1(a[j]);
pipei2(a[j]);
cout<<endl;
for(n=0;n<k;n++)
{
cout<<A[n];
}
cout<<endl;
}
return 0;
}
void pipei1(char x)
{
if(j<k)
{
if(i<0)
i=0;
if(x=='(')
{
i++;
}
else if(x==')')
{
if(i==0)
{
A[j]='?';
}
i--;
}
j++;
pipei1(a[j]);
}
}
void pipei2(char x)
{
if(j>=0)
{
if(m<0)
m=0;
if(x==')')
{
m++;
}
else if(x=='(')
{
if(m==0)
{
A[j]='$';
}
m--;
}
j--;
pipei2(a[j]);
}
}
|
17 | 8315 | int main()
{
char chuan[101],shuchu[100];
int count1,count2,length,i,j;
while(cin>>chuan)
{
cout<<chuan<<endl;
length=strlen(chuan);//?????
strcpy(shuchu,chuan);//????????????????
count1=0;
count2=0;
for(i=0;i<length;i++)
{
if(chuan[i]=='(')count1++;
if(chuan[i]==')')
{
count2++;
if(count2>count1)
{
shuchu[i]='?';
count2--;
}//??????????????????????????????
}
}//?????????
count1=0;
count2=0;
for(i=length-1;i>=0;i--)
{
if(chuan[i]==')')count2++;
if(chuan[i]=='(')
{
count1++;
if(count1>count2)
{
shuchu[i]='$';
count1--;
}//??????????????????????????????
}
}//?????????
shuchu[length]='\0';
for(i=0;i<length;i++)
{
if(shuchu[i]!='?' && shuchu[i]!='$')shuchu[i]=' ';
}//?????????
cout<<shuchu<<endl;
memset(shuchu,0,sizeof(shuchu));
memset(chuan,0,sizeof(chuan));
}
return 0;
} |
17 | 8316 | int main()
{
int n;
int i;
int t;
scanf("%d",&n);
scanf("\n");
char c[101]={0};
char d[101]={0};
int j=0,k=0;
for(i=0;i<n;i++)
{
for(j=0;j<101;j++)
{
c[j]=0;
d[j]=0;
}
scanf("%s",c);
t=strlen(c);
for(j=0;j<t;j++)
{
d[j]=c[j];
}
for(j=0;j<t;j++)
{
if(c[j]!='('&&c[j]!=')') c[j]=' ';
if(c[j]==')')
{
for(k=j-1;k>=0;k--)
{
if(c[k]=='(')
{
c[k]=' ';
c[j]=' ';
break;
}
}
}
}
for(j=0;j<t;j++)
{
if(c[j]=='(')
{
c[j]='$';
}
else if(c[j]==')')
{
c[j]='?';
}
}
printf("%s",d);
printf("\n");
printf("%s",c);
printf("\n");
}
return 0;
} |
17 | 8317 | int findl(int i,char a[102],int n);
int find(int i,char a[102]);
int main()
{
char a[102];
memset (a,'\n',102);
while(cin >>a)
{
int n=strlen(a);
cout <<a <<endl;
for (int i=0;i<n;i++)
{
int x=0;
if (a[i]=='('&&findl(i,a,n)>n) cout <<"$"; //????
else if (a[i]==')'&&find(i,a)<0) cout <<'?';
else cout <<" ";
}
cout <<endl;
}
}
int findl(int i,char a[102],int n) //????????
{
int k=i+1;
while (k<n)
{
if (a[k]=='(') k=findl(k,a,n); //????????????
else if (a[k]==')') return k;
k++;
}
return n+1;
}
int find(int i,char a[102]) //???????
{
int k=i-1;
while (k>=0)
{
if (a[k]==')') k=find (k,a);
else if (a[k]=='(') return k;
k--;
}
return -1;
} |
17 | 8318 | /*
* 3704:??????
*
* Created on: 2012-12-1
* Author: zhuyongfu
*/
char s[101];//?????????????
int l;//??????
int f(int k){//????
int i,j;
for(i = k;i >= 0;i--)//??????
if(s[i] == '(')
{
for(j = i + 1;j < l;j++)
if(s[j] == ')')//????????????
{
s[i] = 'a';//?????????
s[j] = 'a';
k = i;
return f(k);//??
}
}
for(i = 0;i < l;i++)//??
{
if(s[i] == '(')
cout << '$';
else if(s[i] == ')')
cout << '?';
else
cout << ' ';
}
cout << endl;
return 0;
}
int main(){
while(cin.getline(s,101,'\n')){//??
l = strlen(s);
cout << s << endl;
f(l - 1);//????
memset(s,'\0',sizeof(s));//??
}
return 0;
} |
17 | 8319 | int main()
{
char a[105];
while(gets(a))
{
int n=strlen(a);int i=0,j,b[105];
for(i=0;i<n;i++)
{
if(a[i]=='('){b[i]=1;}
else if(a[i]==')'){b[i]=-1;}
else b[i]=0;
}//first step:change char a[] to int b[].
for(i=0;i<n;i++)
{
if(b[i]==-1)
{
for(j=i;j>=0;j--)
{
if(b[j]==1)
{
b[i]=0;b[j]=0;break;
}
}
}
}
puts(a);printf("\n");
for(i=0;i<n;i++)
{
if(b[i]==0)
printf(" ");
else if(b[i]==1)
printf("$");
else printf("?");
}
printf("\n");
}
return 0;
}
|
17 | 8320 | int main()
{
char str[110];
int i=0,j=0;
while(cin.getline(str,110))
{
for(i=0;str[i]!='\0';i++) //???????
{
cout<<str[i];
}
cout<<endl;
for(i=0;str[i]!='\0';++i) //????????????????????????????????????
{
if(str[i]==')')
{
for(j=i-1;j>=0;--j)
{
if(str[j]=='(')
{
str[i]=str[j]=' ';
break;
}
}
}
}
for(i=0;i<strlen(str);++i) //??????????????
{
if(str[i]=='(')
cout<<"$";
else if(str[i]==')')
cout<<"?";
else
cout<<" ";
}
cout<<endl;
}
return 0;
} |
17 | 8321 | int show(char a[],int t)
{int i,k,l,j=1;
static int b[101];
puts(a);
for(i=0;i<=t-1;i++)
switch(a[i])
{case '(':a[i]=' ';
b[j]=i+1;
j++;
break;
case ')':a[i]=' ';
b[j]=-(i+1);
j++;
break;
default: a[i]=' ';
}
j--;
do
{
l=0;
for(k=1;k<=j-1;k++)
if(b[k]>0)
{for(i=k+1;i<=j;i++)
if(b[i]!=0)
break;
if(b[k]*b[i]<0)
{b[k]=0;b[i]=0;l++;}}
}
while(l>0);
for(i=1;i<=j;i++)
{if(b[i]<0)
a[-b[i]-1]='?';
else if(b[i]>0)
a[b[i]-1]='$';
}
puts(a);
return 0;
}
int main()
{int i,n;
scanf("%d\n",&n);
for(i=1;i<=n;i++)
{char a[101];int t;
gets(a);
t=strlen(a);
show(a,t);}
return 0;} |
17 | 8322 | int main()
{
int n;
scanf("%d",&n);
char c[10000];
int i;
for(i=0;i<n;i++)
{
scanf("%s",c);
printf("%s\n",c);
int j,x;
x=strlen(c);
for(j=0;j<x;j++)
{
if(c[j]!='('&&c[j]!=')')
{
c[j]=' ';
}
}
for(j=0;j<x;j++)
{
if(c[j]==')')
{
int m;
for(m=j;m>=0;m--)
{
if(c[m]=='(')
{
c[m]=' ';
c[j]=' ';
break;
}
}
}
}
for(j=0;j<x;j++)
{
if(c[j]=='(')
{
c[j]='$';
}
else if(c[j]==')')
{
c[j]='?';
}
}
printf("%s\n",c);
}
return 0;
}
|
17 | 8323 |
//?????????????????????????????????????
//???????????????;break;???????
//??????????????????
int main(int argc, char* argv[])
{
char s[100];
int i,j;
while(scanf("%s",s)!=EOF)
{
puts(s);
int a[100]={0};
for(i=0;s[i]!='\0';i++)
if(s[i]=='(')
a[i]=-1;
else if(s[i]==')')
a[i]=1;
for(i=0;s[i]!='\0';i++)
if(a[i]==1)
for(j=i-1;j>=0;j--)
if(a[j]==-1)
{
a[i]=a[j]=0;
break;
}
for(i=0;s[i]!='\0';i++)
if(a[i]==1) printf("?");
else if(a[i]==-1) printf("$");
else if(a[i]==0) printf(" ");
printf("\n");
}
return 0;
} |
17 | 8324 | void find(char a[],int n,int m)
{
int i;
if(a[m]!=')'&&m<n)
{find(a,n,m+1);}//??????????
if(a[m]==')'&&m<n)
{
for(i=m;i>=0;i--)
{
if(a[i]=='(')
{a[i]=' ';a[m]=' ';break;}//????????
}
find(a,n,m+1);//????
}
}
int main()
{
int n;
char a[200];
while(cin>>a)//??
{
cout<<a<<endl;//??????
n=strlen(a);
find(a,n,0);//????????
for(int k=0;k<n;k++)
{
if(a[k]=='(')
{a[k]='$';}//???????
else
{if(a[k]==')')//???????
{a[k]='?';}
else
{if(a[k]!='('&&a[k]!=')')//?????????
{a[k]=' ';}
}
}
}
cout<<a<<endl;//???????
}
return 0;
} |
17 | 8325 | //****************************************
//*????????? **
//*?????? 1100012763 **
//*???2011.11.15 **
//****************************************
int main()
{
char array[101] , ans[101];
int len , i , left , right;
while (cin.getline(array , 101))
{
len = strlen(array);
left = 0;
right = 0;
for (i = 0; i < len; i++)
{
ans[i] = ' ';
if (array[i] == '(')
{
left++;
}
if (array[i] == ')')
{
right++;
if (right > left)
{
left = 0;
right = 0;
ans[i] = '?';
}
}
}
left = 0;
right = 0;
for (i = len - 1; i >=0; i--)
{
if (array[i] == '(')
{
left++;
if (left > right)
{
left = 0;
right = 0;
ans[i] = '$';
}
}
if (array[i] == ')')
{
right++;
}
}
for (i = 0; i < len; i++)
cout << array[i];
cout << endl;
for (i = 0; i < len; i++)
cout << ans[i];
cout << endl;
}
return 0;
}
|
17 | 8326 | int main(){
char string[101];//??????
int i,j,lenth,n,t;
while(cin.getline(string,101)){//??????????????
n=0;
lenth=strlen(string);//????
cout<<string<<endl;//????????
for(i=0;i<lenth;i++){//??????????????????????
if(string[i]=='(') string[i]='$';
else if(string[i]==')') string[i]='?';
else{
string[i]=' ';
n++;
}
}
n=(lenth-n)/2;//?????????????
for(i=0;i<n;i++){//??
for(j=0;j<lenth;j++){
for(t=j+1;t<lenth;t++){
if(string[j]=='$'&&string[t]=='$'){
j=t;
continue;
}
if(string[j]=='$'&&string[t]=='?'){
string[j]=string[t]=' ';
j=t-1;
}
}
}
}
for(i=lenth-1;i>=0;i--){//??????
if(string[i]!=' ') break;
}
string[i+1]='\0';
lenth=strlen(string);
int m=0;
for(i=0;i<lenth;i++){//??????
if(string[i]!=' ') break;
m++;
}
for(i=m;i<lenth;i++)
cout<<string[i];
cout<<endl;
}
return 0;
}
|
17 | 8327 |
struct bracket
{
char data[max];
int top;
};
int main()
{
char str[max], flag[max];
int i, j, len,n;
struct bracket *leftbracket, *rightbracket;
scanf("%d\n",&n);
for(j=0;j<n;j++)
{
scanf("%s",str);
//????
leftbracket = (struct bracket *)malloc(sizeof(struct bracket));
rightbracket = (struct bracket *)malloc(sizeof(struct bracket));
leftbracket->top = rightbracket->top = 0;
len = strlen(str);
//?????????????
for(i = 0; i < len; i ++)
{
switch(str[i])
{
case '(' :
leftbracket->data[leftbracket->top ++] = str[i];
flag[i] = ' ';
break;
case ')' :
if(leftbracket->top > 0)
{
flag[i] = ' ';
leftbracket->top -= 1;
}else
{
flag[i] = '?';
}
break;
default :
flag[i] = ' ';
break;
}
}
//?????????????
for(i = len - 1; i >= 0; i --)
{
switch(str[i])
{
case ')' :
rightbracket->data[rightbracket->top ++] = str[i];
break;
case '(' :
if(rightbracket->top > 0)
{
rightbracket->top -= 1;
}else
{
flag[i] = '$';
}
break;
default :
break;
}
}
flag[len]='\0';
//????
printf("%s\n%s\n", str, flag);
//?????
memset(str, '\0', sizeof(str));
memset(flag, '\0', sizeof(flag));
}
return 0;
} |
17 | 8328 | int getlength(char* a)//???????
{
int i=0;
while(a[i]!='\0')
i++;
return i;
}
void chuli(char ch[],int a[],int n)//???????????int???
{
for(int i=0;i<n;i++)
{
switch(ch[i])
{
case '(':a[i]=1;break;
case ')':a[i]=-1;break;
default :a[i]=0;break;
}
}
}
void pipei(int a[],int n)//????????
{
for(int k=0;k<n;k++)
{
if(a[k]==1)
{
int s=0;
for(int i=0;i<k;i++)
s+=a[i];
for(int i=k;i<n;i++)
{
if(a[i]==-1)
{
int t=0;
for(int j=0;j<i;j++)
t+=a[j];
if(s==t-1)//????
{a[k]=0;a[i]=0;break;}//??????0
}
}
}
}
}
int main()
{
while(cin.peek()!=EOF)
{
char ch[110];
cin.getline(ch,110,'\n');
int a[110];
int n=getlength(ch);
chuli(ch,a,n);
pipei(a,n);
cout<<ch<<endl;
for(int i=0;i<n;i++)//??
{
switch(a[i])
{
case 1:cout<<'$';break;
case -1:cout<<'?';break;
case 0:cout<<' ';break;
}
}
cout<<endl;
}
return 0;
} |
17 | 8329 | int main()
{
char l,r,s,sen[200],rem[200];
int i=1,j=1,k=1,nsen,b=1;
l='(';r=')';
while(b==1)
{
while((s = cin.get())!='\n')
{sen[i]=s;rem[i]=s;i++;
}nsen=i-1;
for(j=1;j<nsen;j++)//??????
for(i=1;i<nsen;i++)
if(sen[i]==l && sen[i+j]==r)
{sen[i]=' ';sen[i+j]=' ';}//?????????????
for(i=1;i<=nsen;i++)
if(sen[i]==l)sen[i]='$';
else if(sen[i]==r)sen[i]='?';//?????????
else sen[i]=' ';//?????????
for(i=1;i<=nsen;i++)
cout<<rem[i];
cout<<endl;
for(i=1;i<=nsen;i++)
cout<<sen[i];
cout<<endl;
nsen=0;i=1;j=1;k=1;
}
return 0;
}
|
17 | 8330 | void kuohao(char c[])
{
int i,j,n;
for(n=0;c[n]!='\0';n++);//???????
for(i=n-1;i>=0;i--)
{
if(c[i]=='(')
{
for(j=i+1;c[j]!='\0';j++)
if(c[j]==')')
{c[i]=c[j]=' ';break;}
if(c[j]=='\0')//??????????????????????$
{c[i]='$';}
kuohao(c);//????
}
}
}
int main()
{
char c[110]={'\0'};
int i;
while(cin.getline(c,101))
{cout<<c<<endl;
for(i=0;c[i]!='\0';i++)
if(c[i]!='('&&c[i]!=')')
c[i]=' ';//????????????
kuohao(c);
for(i=0;c[i]!='\0';i++)
if(c[i]==')')
c[i]='?';//???????????
cout<<c<<endl;}
return 0;
}
|
17 | 8331 | char a[1000];
int n, c1 = 0;
int match(int c)
{
for(int i = c; i < n; i++)
{
if(a[i] != '(' && a[i] != ')' && a[i] != '$')
a[i] = ' ';
if(a[i] == '(')
{
c1 ++;
if(match(i + 1) != 0)
{
a[i] = ' ';
a[match(i + 1)] = ' ';
c1 --;
}
else
a[i] = '$';
}
if(a[i] == ')')
{
if(c1 == 0)
{
a[i] = '?';
if(i < n)
{
match(i + 1);
return 0;
}
}
return i;
}
}
return 0;
}
int main() //???
{
while(cin>>a)
{
c1 = 0;
n = strlen(a);
cout<<a<<endl;
match(0);
cout<<a<<endl<<endl;
}
return 0;
} //?????
|
17 | 8332 | int main()
{
char ch1[101],ch2[101];
int i=0,j=0,k=0,len=0;
while(cin.getline(ch1,101))
{
len=strlen(ch1);
int num=0;
for(i=0;i<len;i++)
{
ch2[i]=' ';
if(ch1[i]=='(')
{
ch2[i]='$';
num++;
}
if(ch1[i]==')')
{
ch2[i]='?';
num--;
if(num==0)
{
ch2[i]=' ';
for(j=0;j<i;j++)
{
if(ch1[j]=='(')
{
for(k=j;k<=i;k++)
{
ch2[k]=' ';
break;break;
}
}
}
}
if(num>0)
{
ch2[i]=' ';
for(j=i;j>=0;j--)
{
if(ch2[j]=='$')
{
ch2[j]=' ';
break;
}
}
}
if(num<0)
num=0;
}
}
ch2[len]='\0';
cout<<ch1<<endl;
cout<<ch2<<endl;
}
return 0;
} |
17 | 8333 | int main()
{
char a[101]; //?????a[101]????????????
int s[101],len,k=0,i; //????s[101]???????len????????k????????;i??????
while(cin>>a)
{
for(len=0;a[len]!='\0';len++); //????????
cout<<a<<endl;
for(i=0;i<len;i++) //????????????
{
if(a[i]=='(') //?a[i]?'('??a[i]???
s[k++]=i;
if(a[i]==')'&&k>0) //?a[i]?')'???????????'('??????
{
a[s[--k]]=' ';
a[i]=' ';
}
if(a[i]!='('&&a[i]!=')') //?a[i]??????????
a[i]=' ';
if(a[i]==')'&&k==0)
a[i]='?';
}
for(i=k-1;i>=0;i--)
a[s[i]]='$';
cout<<a<<endl;
memset(a,0,sizeof(a)); //??????
k=0;
}
return 0;
} |
17 | 8334 |
int main()
{
char s[101] = {0};
while ( (scanf("%s", s) != EOF) )
{
int i,j;
int you=0;
int l1=strlen(s);
char a[101];
strcpy(a,s);
for(i=l1-1;i>=0;i--)
{
if(s[i]=='(')
{
you=0;
for(j=i+1;j<l1;j++)
{
if(s[j]==')')
{
s[i]=' ';
s[j]=' ';
you=you+1;
break;
}
}
if(you==0) s[i]='$';
}
}
puts(a);
for(i=0;i<l1;i++)
{
if(s[i]=='?'||s[i]=='$') printf("%c",s[i]);
else if(s[i]==')') printf("?");
else printf(" ");
}
printf("\n");
}
return 0;
}
|
17 | 8335 | int len;
void f(char a[])
{
int i,j;
len=strlen(a);
for(i=len-1;i>=0;i--)
{
if(a[i]=='(')
{
for(j=i+1;j<len;j++)
{
if(a[j]==')')
{
a[i]=a[j]=' ';
break;
}
}
if(a[j]=='\0')
{
a[i]='$';
}
f(a);
}
}
}
int main()
{
char c[110]={'\0'};
int i;
while(cin.getline(c,101))
{cout<<c<<endl;
for(i=0;c[i]!='\0';i++)
if(c[i]!='('&&c[i]!=')')
c[i]=' ';//????????????
f(c);
for(i=0;c[i]!='\0';i++)
if(c[i]==')')
c[i]='?';//???????????
cout<<c<<endl;}
return 0;
}
|
17 | 8336 | int main()
{
char string[1000];
int i=0,j=0,length=0,t1=0,t2=0;
int flag=0,left=0,right=0;
while ( gets( string ) )
{
cout<<string<<endl;
length=strlen(string);
flag=1,left=0,right=0; //???
t1=0,t2=0; //???
while ( flag==1 )
{
for ( i=0;i<length;i++ )
{
if ( string[i]=='(' )
{
left=i;
t1=1;
}
//????????,?????????,???????????
else if ( t1==1 && string[i]==')' )
{
right=i;
t2=1;
break;
}
//??,?????????????????,??????break????????
else
continue;
}
if ( t1==1 && t2==1 )
//??????????????????????????????'0'
{
string[left]='0';
string[right]='0';
t1=0;
t2=0;
flag=1;
}
else //?????????????????????????????????????????
flag=0;
//cout<<string<<endl;
}
for ( i=0;i<length;i++ ) //??????????????
{
if ( string[i]=='(' )
string[i]='$';
else if ( string[i]==')' )
string[i]='?';
else
string[i]=' ';
}
for ( i=0;i<length;i++ )
{
cout<<string[i];
}
cout<<endl;
}
return 0;
} |
17 | 8337 | void zhengli(char a[])
{
void panduan(char a[]);
int i,k,j;
k=strlen(a);
for(j=0;j<50;j++)
{
for(i=0;i<k;i++)
{
if(a[i]=='$')
a[i]='(';
else if(a[i]=='?')
a[i]=')';
}
panduan(a);
}
}
void panduan(char a[])
{
int i,k,flag=0,j;
char b[110];
k=strlen(a);
b[k]='\0';
for(i=0;i<k;i++)
{
if(a[i]!='('&&a[i]!=')')
b[i]=' ';
else if(a[i]=='(')
{
if(flag==1)
{
b[j]='$';
j=i;
b[j]='$';
}
else
{
flag=1;
j=i;
b[j]='$';
}
}
else
{
if(flag==1)
{
b[j]=' ';
flag=0;
b[i]=' ';
}
else
{
b[i]='?';
}
}
}
strcpy(a,b);
}
void main()
{
int i,k;
char a[110];
scanf("%d",&k);
for(i=0;i<k;i++)
{
scanf("%s",a);
printf("%s\n",a);
panduan(a);
zhengli(a);
printf("%s\n",a);
}
}
|
17 | 8338 |
char num2[110] = {'\0'};
int left(char num[110], int point, int sum, int l) { // check if it is a wrong '('
if(point == l) { // finish the function
if(num[point] == '(') {
num2[point] = '$';
return 0;
}
if(num[point] == ')') {
sum = 1;
return sum;
}
if(num[point] != '(' && num[point] != ')') return 0;
}
else {
int k = left(num, point + 1, sum, l);
if(num[point] == '(' && k == 0) {
num2[point] = '$';
return 0;
}
if(num[point] == '(' && k != 0) {
sum = k - 1;
return sum;
}
if(num[point] == ')') {
sum = k + 1;
return sum;
}
if(num[point] != '(' && num[point] != ')')
return k;
}
}
int right(char num[110], int point, int sum, int l) { // check if it is a wrong '('
if(point == l) { // finish the function
if(num[point] == ')') {
num2[point] = '?';
return 0;
}
if(num[point] == '(') {
sum = 1;
return sum;
}
if(num[point] != '(' && num[point] != ')') return 0;
}
else {
int k = right(num, point - 1, sum, l);
if(num[point] == ')' && k == 0) {
num2[point] = '?';
return 0;
}
if(num[point] == ')' && k != 0) {
sum = k - 1;
return sum;
}
if(num[point] == '(') {
sum = k + 1;
return sum;
}
if(num[point] != '(' && num[point] != ')')
return k;
}
}
int main() {
char num[110] = {'\0'};
while(cin >> num) {
int l = strlen(num); // store the total length of the num
cout << num << endl;
for(int i = 0; i < l; i++) // build a new num to show the wrong '(' and ')'
num2[i] = ' ';
num2[l] = '\0';
left(num, 0, 0, l - 1);
right(num, l - 1, 0, 0);
cout << num2 << endl;
}
return 0;
} |
17 | 8339 |
int main(){
char chuan[101];
while(scanf("%s",chuan)!=EOF){
printf("%s\n",chuan);
int i,j,k,p;
int sig=0;
p=strlen(chuan)-1;
for(i=p;i>=0;i--){
if(chuan[i]==')') sig++;
if((chuan[i]!='(')&&(chuan[i]!=')')) chuan[i]=' ';
if((sig!=0)&&(chuan[i]=='(')){
chuan[i]=' ';sig=sig-1;
for(j=i+1;j<=p;j++)
if(chuan[j]==')'){
chuan[j]=' ';break;}}}
for(i=0;i<=p;i++){
if(chuan[i]=='(') printf("$");
else if(chuan[i]==')') printf("?");
else printf(" ");}
printf("\n");
}
return 0;
} |
17 | 8340 | int main()
{
int i,n=0,k,p,count1=0,count2=0;
char a[100][1000],b[1000][1000];
for(i=0;i<100;i++)
{
for(k=0;k<100;k++)
{
b[i][k]=' ';
}
}
for(i=0;i<100;i++)
{
scanf("%s",a[i]);
n++;
if(a[i][0]=='\0')
break;
}
for(i=0;i<n;i++)
{
printf("%s\n",a[i]);
for(k=0;k<strlen(a[i]);k++)
{
if(a[i][k]==')')
{
for(p=k-1;p>=0;p--)
{
if(a[i][p]=='('){
a[i][p]='.';
a[i][k]='.';
break;
}
else if(a[i][p]==')'){
break;
}
}
}
}
for(k=0;k<strlen(a[i]);k++)
{
if(a[i][k]=='(')
b[i][k]='$';
else if(a[i][k]==')')
b[i][k]='?';
}
b[i][strlen(a[i])]='\0';
printf("%s\n",b[i]);
}
return 0;
} |
17 | 8341 | int main()
{
char a[A];
int i,j,n;
while(scanf("%s",a)!=EOF)
{
printf("%s\n",a);
n=strlen(a);
for(i=0;i<n;i++)
{
if(a[i]==')')
{
for(j=i-1;j>=0;j--)
{
if(a[j]=='(')
{
a[j]=0;
a[i]=0;
break;
}
}
}
}
for(i=0;i<n;i++)
{
if(a[i]=='(') {printf("$");continue;}
if(a[i]==')') {printf("?");continue;}
printf(" ");
}
printf("\n");
}
return 0;
} |
17 | 8342 | int main()
{
char str[1001];int n;
while(~scanf("%s",str))
{
n=strlen(str);
printf("%s",str);
printf("\n");
for(int i=1;i<n;i++)
{
if(str[i]==')')
{
for(int j=i-1;j>=0;j--)
{if(str[j]=='(') {str[i]=' ';str[j]=' ';break;}}
}
}
for(int i=0;i<n;i++)
{
if(str[i]=='(') str[i]='$';
else if(str[i]==')') str[i]='?';
else str[i]=' ';
}
printf("%s",str);
printf("\n");
}
} |
17 | 8343 |
int main()
{
char a[101];
int i, j, len;
while (cin >> a)
{
cout << a << endl;
len = strlen(a);
for (i = 1; i < len; i++)
{
for (j = 0; j < len - i; j++)
{
if (a[j] == '(' && a[j + i] == ')')
{
a[j] = ' ';
a[j + i] = ' ';
}
if (a[j] != '(' && a[j] != ')')
{
a[j] = ' ';
}
}
}
for (i = 0; i < len; i++)
{
if (a[i] == '(')
{
a[i] = '$';
}
if (a[i] == ')')
{
a[i] = '?';
}
}
cout << a << endl;
}
return 0;
} |
17 | 8344 | int j=1;
int main()
{ char a[101];
a[0]=0;
l: scanf("%s",a);
if(a[0]==0) return 0;
else
printf("%s\n",a);
int r,i,k;
r=strlen(a);
for(i=r-1;i>=0;i--)
{if(a[i]!='('&&a[i]!=')') a[i]=' ';
else if(a[i]=='(')
{for(k=i;k<=r-1;k++){ if(a[k]==')') {a[i]=' ';a[k]=' ';break;}}}
}
for(i=0;i<=r-1;i++)
{if(a[i]=='(') a[i]='$';
else if(a[i]==')') a[i]='?';
}
printf("%s\n",a);
return main();
}
|
17 | 8345 | int main()
{
char str[101];
int i , j , a[101] , len , count;
while (cin.getline(str , 101))
{
count = 0;
len = strlen(str);
for (i = 0 ; i <= len -1 ; i++)
{
cout << str[i];
}
cout << endl;
for (i = 0 ; i <= len - 1 ; i++)
{
if (str[i] == ')')
{
count++;
a[count] = i;
}
}
for (i = 1 ; i <= count ; i++)
{
for (j = a[i] - 1 ; j >= 0 ; j--)
{
if (a[i] == 0)
{
str[a[i]] = '?';
}
if (str[j] == '(')
{
str[j] = ' ';
str[a[i]] = ' ';
break;
}
}
if (str[a[i]] != ' ')
{
str[a[i]] = '?';
}
}
for (i = 0 ; i <= len -1 ; i++)
{
if (str[i] == '(')
{
str[i] = '$';
}
}
for (i = 0 ; i <= len -1 ; i++)
{
if ((str[i] != ' ')&&(str[i] != '?')&&(str[i] != '$'))
{
str[i] = ' ';
}
}
for (i = 0 ; i <= len -1 ; i++)
{
cout << str[i];
}
cout << endl;
}
return 0;
} |
17 | 8346 | char a[200],b[200];
int l;
void f36(int i)
{
int j;
for(j=i+1;j<l;j++)
{
if(b[j]!=32)
{
if(b[j]==63) {b[j]=32;b[i]=32;}
break;
}
}
}
int g(void)
{
gets(a);
if(a[0]==0) return 0;
else return 1;
}
void k(void)
{
l=strlen(a);
int i,n=0,p;
for(i=0;i<l;i++)
{
b[i]=32;
if(a[i]==40) {b[i]=36; n=n+1;}
if(a[i]==41) {b[i]=63; n=n+1;}
}
for(p=1;p<=n;p++)
for(i=0;i<l;i++)
{
if(b[i]==36) f36(i);
}
printf("%s\n",a);
for(i=0;i<l;i++) printf("%c",b[i]);
printf("\n");
a[0]=0;
}
int main()
{
int n=1;
while(n==1)
{
n=g();
if(n==0) break;
k();
}
return 0;
} |
17 | 8347 | char investigate(char a[])
{
int i,j,k,n;
int p1=0,p2=0,w,t=0,t1=0;
n=strlen(a);
char b[100];
for(i=0;i<n;i++)
{
if(a[i]=='(') p1++;
if(a[i]==')') p2++;
}
for(i=0;i<n;i++)
{
if((i==(n-1))&&(t>t1))
{
i=-1;t1=t;goto loop;
}else
if(a[i]!='('){b[i]==' ';continue;}
else
{
for(j=i+1;j<n;j++)
{
if(a[j]=='('){i=j-1;break;}
else if(a[j]==')')
{
a[i]='[';a[j]=']';t++;
break;
}
}
}
loop:;
}
for(i=0;i<n;i++)
{
if(a[i]=='(') b[i]='$';
else if(a[i]==')') b[i]='?';
else b[i]=' ';
}
for(i=0;i<n;i++)
{
if(a[i]=='[')a[i]='(';
if(a[i]==']')a[i]=')';
}
for(i=0;i<n;i++)
printf("%c",a[i]);
printf("\n");
for(i=0;i<n;i++)
printf("%c",b[i]);
return 0;
}
int main()
{
int i,j;
char a[100];
while(gets(a))
{
investigate(a);
printf("\n");
}
}
|
17 | 8348 | int main()
{
char s[101];
int i,l,j;
while(gets(s)!=0)
{ puts(s);
printf("\n");
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]==')')
{
for(j=i-1;j>=0;j--)
{
if(s[j]=='(')
break;
}
if(j>=0)
{
s[i]=' ';
s[j]=' ';
}
}
}
for(i=0;i<l;i++)
{
if(s[i]=='(')
s[i]='$';
else if(s[i]==')')
s[i]='?';
else s[i]=' ';
}
puts(s);
printf("\n");
}
return 0;
}
|
17 | 8349 | int find(char s[], int pos)
{
int i, p=0, q=0;
if (pos<0)
return 0; //?????
if (s[pos]==')')
for (i=pos-1; i>=0; i--)
{
if (s[i]=='(')
p++;
if (s[i]==')')
q++; //??????????????
if ((s[i]=='(')&&(p-q==1))
{
s[i]=' ';
s[pos]=' ';
break; //?????????????
}
}
find(s,pos-1); //??????
return 0;
}
int main()
{
char s[101], ss[101], ans[101];
int i, n;
while (true)
{
cin >> s;
if (!cin)
break;
strcpy(ss,s);
memset(ans,' ',sizeof(ans));
n=strlen(s)-1; //??????
find(s,n); //???????
for (i=0; i<=n; i++)
{
if (s[i]=='(')
ans[i]='$';
if (s[i]==')')
ans[i]='?'; //????????????
}
ans[n+1]='\0';
cout << ss << endl;
cout << ans << endl; //????????
}
return 0; //main???????0
} |
17 | 8350 | int main()
{
char a[105];
int mm;scanf("%d",&mm);
while(mm--)
{
while(gets(a))
{
int n=strlen(a);int i=0,j,b[105];
for(i=0;a[i];i++)
{
if(a[i]=='('){b[i]=1;}
else if(a[i]==')'){b[i]=-1;}
else b[i]=0;
}//first step:change char a[] to int b[].
for(i=0;i<n;i++)
{
if(b[i]==-1)
{
for(j=i;j>=0;j--)
{
if(b[j]==1)
{
b[i]=0;b[j]=0;break;
}
}
}
}
puts(a);printf("\n");
for(i=0;i<n;i++)
{
if(b[i]==0)
printf(" ");
else if(b[i]==1)
printf("$");
else printf("?");
}
printf("\n");
}
}
return 0;
} |
17 | 8351 | int main()
{
char ch[101];
int i,a[101],k,j;
for(i=0;i<=100;i++)
a[i]=1;
while(scanf("%s",ch)!=EOF)
{
puts(ch);
i=0;
do
{
if((ch[i]>='a' && ch[i]<='z') || (ch[i]>='A' && ch[i]<='Z'))
a[i]=0;
if(ch[i]==')')
{
for(k=i-1;k>=0;k--)
{
if((ch[k]=='(') && a[k]==1)
{
a[k]=0;
a[i]=0;
break;
}
}
}
i++;
}
while(ch[i]!='\0');
j=i-1;
for(i=0;i<=j;i++)
{
if(a[i]==0)
printf(" ");
else
{
if(ch[i]=='(')
printf("$");
else
printf("?");
}
}
printf("\n");
for(i=0;i<=100;i++)
{
a[i]=1;
ch[i]='a';
}
}
return 0;
} |
17 | 8352 | int k,m=0;
char a[100]={'\0'};
void pipei(int m,char a[])
{
int i,j;
for(i=m;i<=k-1;i++)
{
if(a[i]==')') {break;}
if(a[i]!='('&&a[i]!=')') {a[i]=' ';}
}
m=i+1;
for(j=i;j>=0;j--)
{
if(i==k&&a[k-1]!=')') break;
if(a[j]=='(') {a[j]=' ';a[i]=' ';break;}
}
if(m<=k-1) pipei(m,a);
}
int main()
{
char w;
while(cin>>a)
{
k=strlen(a);
int i,j;
cout<<a<<endl;
pipei(0,a);
for(i=0;i<=k-1;i++)
{
if(a[i]=='(')
a[i]='$';
if(a[i]==')')
a[i]='?';
}
for(i=0;i<=k-1;i++)
cout<<a[i];
cout<<endl;
for(i=0;i<100;i++)
{ a[i]='\0';}
}
return 0;
}
|
17 | 8353 | char a[200];
void match(char a[])
{
int s;
s=strlen(a);
if(s==0) return;
int i,j;
int check=0;
for(i=0;i<s-1;i++)
{
if(a[i]=='(')
{
for(j=i+1;j<s&&a[j]==' ';j++);
if(j<s)
{
if(a[j]==')')
{
check=1;
break;
}
}
}
}
if(check==1)
{
a[i]=' ';
a[j]=' ';
match(a);
}
if(check==0)
return;
}
int main()
{
int n;
scanf("%d",&n);
char temp;
scanf("%c",&temp);
while(n--)
{
gets(a);
puts(a);
int s;
s=strlen(a);
int i;
for(i=0;i<s;i++)
if(a[i]!='('&&a[i]!=')') a[i]=' ';
match(a);
for(i=0;i<s;i++)
{
if(a[i]=='(') a[i]='$';
else if(a[i]==')') a[i]='?';
}
puts(a);
}
return 0;
} |
17 | 8354 |
//????????????????
//????????????
//???????????????? time limit ????
char b[110];
char a[110];
int opr(int i) //bug1???????
{
int j;
for(j=i-1;j>=0;j--)
{
if(b[j]=='$')
{
b[j]=' ';
b[i]=' ';
break;
}
}
return 0;
}
void tag(char*a, char*b) //????2??????
{
int l=strlen(a);
int i;
for(i=0;i<l;i++)
{
if(a[i]=='(')
b[i]='$';
else
if(a[i]==')')
b[i]='?';
else
b[i]=' ';
}
b[l]='\0';
}
int main()
{
int i,l;
while(scanf("%s",a)!=EOF) //??
{
l=strlen(a);
printf("%s\n",a); //??
tag(a,b);
for(i=0;i<l;i++)
{
if(b[i]=='?') //????
{
opr(i);
}
}
printf("%s\n",b);
}
return 0;
} |
17 | 8355 | int main()
{
void match(char *ps, char *pf, int len);
char a[N] = {'\0'};
while( scanf("%s", a) == 1) {
char b[N] = {'\0'};
match(a, b, strlen(a));
}
return 0;
}
void match(char *ps, char *pf, int len)
{
int i, flag, last, isleft, isright;
char str[N] = {'\0'}, strf[N] = {'\0'};
strcpy(strf, pf);
strcpy(str, ps);
for(i = 0; i < len; i++) {
if(*(str + i) == '(')
*(strf + i) = -1;
else if( *(str + i) == ')' )
*(strf + i) = +1;
}
do {
flag = 0;
last = 0;
isleft = 0;
isright = 0;
for(i = 0; i < len; i++) {
if (*(strf + i) == 1 && flag == 1) {
*(strf + i) = 0;
*(strf + last) = 0;
flag = 0;
isleft = 1;
} else if(*(strf + i) == -1) {
flag = 1;
last = i;
isright = 1;
}
}
} while(isleft && isright);
printf("%s\n", ps);
for(i = 0; i < len; i++) {
if (*(strf + i) == -1)
printf("$");
else if (*(strf + i) == +1)
printf("?");
else
printf(" ");
}
printf("\n");
}
|
17 | 8356 | int main()
{
int n, i, left[102], len, j, k;
char *p = NULL;
char str[102];
cin >> n;
for ( i = 1; i <= n; i++ )
{
k = 0;
cin >> str;
cout << str << endl;
len = strlen(str);
p = str;
for ( ; p < str + len; p++ )
{
if ( *p != '(' && *p != ')' )
*p = ' ';
}
for ( j = 0; j < len; j++ )
{
if ( str[j] == '(' )
{
k++;
left[k] = j;
}
if ( str[j] == ')' )
{
if ( k == 0 )
str[j] = '?';
else
{
left[k] = -1;
k--;
}
}
}
if ( k == 0 )
{
for ( j = 0; j < len; j++ )
{
if ( str[j] != '?' )
cout << " ";
else
cout << str[j];
}
cout <<endl;
}
else
{
for ( ; k > 0; k-- )
str[left[k]] = '$';
for ( j = 0; j < len; j++ )
{
if ( str[j] != '?' && str[j] != '$' )
cout << " ";
else
cout << str[j];
}
cout << endl;
}
}
return 0;
} |
17 | 8357 | int main()
{
char c[110],s[110];
int left,i;
int leftp[110]={0};
while (cin >>c)
{
left=0;i=0;
memset(leftp,0,110*sizeof(int));
memset(s,0,110*sizeof(char));
while (c[i]!='\0')
{
if (c[i]=='(')
{
left++;leftp[left]=i;
}
else
if (c[i]==')')
{
if (left==0)
s[i]='?';
else
{
left--;
}
}
i++;
}
if (left>0)
for (i=1;i<=left;i++)
s[leftp[i]]='$';
cout <<c<<endl;
for (i=0;i<strlen(c);i++)
if ((s[i]=='?')||(s[i]=='$'))
cout <<s[i];
else
cout <<' ';
cout <<endl;
}
return 0;
} |
17 | 8358 | char in[102];
int lenth;
void match(int n)
{
for(int i=0;i<lenth;i++)
{
if(in[i]=='('&&in[i+n]==')')
{
in[i]=' ';
in[i+n]=' ';
}
}
if(n<=lenth-2)
{
match(n+1);
}
}
void print(char in[])
{
for(int i=0;i<lenth;i++)
{
if(in[i]=='(')
in[i]='$';
else if(in[i]==')')
in[i]='?';
else
in[i]=' ';
}
cout<<in<<endl;
}
int main()
{
while(cin>>in)
{
cout<<in<<endl;
lenth=strlen(in);
match(0);
print(in);
}
return 0;
} |
17 | 8359 | void Match(int input_len);
char input[128];
char tmp_input[128];
int main()
{
//freopen("test.txt","r",stdin);
while(scanf("%s",input)!=EOF)
{
strcpy(tmp_input,input);
int input_len=strlen(input);
Match(input_len);
for(int i=0;i<=input_len-1;i++)
{
if(input[i]=='(')
{
input[i]='$';
}
else if(input[i]==')')
{
input[i]='?';
}
else
{
input[i]=' ';
}
}
printf("%s\n",tmp_input);
printf("%s\n",input);
}
return 0;
}
void Match(int input_len)
{
int cur_left=-1,cur_right=-1;
for(int i=0;i<=input_len-1;i++)
{
if(input[i]=='(')
{
cur_left=i;
continue;
}
if(input[i]==')')
{
if(cur_left!=-1)
{
input[cur_left]=' ';
input[i]=' ';
cur_left=-1;
i=-1;
continue;
}
}
}
} |
17 | 8360 | int a;
char s1[101],s2[101];
int main()
{
int n,l,i,j;
scanf("%d",&n);
for(l=0;l<n;l++)
{
memset(s1,0,101);
memset(s2,0,101);
scanf("%s",s1);
a=strlen(s1);
int k[100]={0},b=0;
for(i=0;i<a;i++)
{
if(s1[i]=='('){
for(j=i;j<a;j++)
{
if(s1[j]=='(') k[i]++;
else if(s1[j]==')') k[i]--;
} }
}
for(i=a-1;i>=0;i--)
{
if(s1[i]==')'){
for(j=i;j>=0;j--)
{
if(s1[j]==')') k[i]++;
else if(s1[j]=='(') k[i]--;
} }
}
for(i=0;i<a;i++)
{
if(s1[i]==')')
{
b=0;
for(j=i-1;j>=0;j--) if(s1[j]==')' && k[j]>0) b++;
k[i] -=b;
}
}
for(i=a-1;i>=0;i--)
{
if(s1[i]=='(')
{
b=0;
for(j=i+1;j<a;j++) if(s1[j]=='(' && k[j]>0) b++;
k[i] -=b;
}
}
for(i=0;i<a;i++)
{
if(k[i]>0) {if(s1[i]=='(') s2[i]='$';else if(s1[i]==')') s2[i]='?';}
else s2[i]=' ';
}
printf("%s\n",s1);
for(i=0;i<a;i++) printf("%c",s2[i]);
printf("\n");
}
}
|
17 | 8361 | /*
* wanyi.cpp
*
* Created on: 2012-12-3
* Author: 7
*/
char a[150];
char b[150];
int sig[150];
int main()
{
int i,k=0;
while(cin>>a)
{
k=0;
int l=strlen(a);
for(i=0;i<l;i++)
{
b[i]=a[i];
if(a[i]=='(')
{
b[i]='$';
sig[k]=i;
k++;
}
if(a[i]==')')
{
k--;
if(k<0)
{b[i]='?';k=0;}
else
{
b[sig[k]]='a';
}
}
}
cout<<a<<endl;
for(i=0;i<l;i++)
{
if(b[i]!='$'&&b[i]!='?')
cout<<" ";
else
cout<<b[i];
}
cout<<endl;
}
}
|
17 | 8362 | /*??????
*?????function3-4.cpp
*Created on: 2012-12-4
*?????????
*/
char input[105], output[105];//??????
void f()
{
memset(output, 0, sizeof(output));//
int l = 0, r = 0;
int len = strlen(input);
int i;
for (i = 0; i < len; ++i)
{
output[i] = ' ';
if (input[i] == ')')
{
if (l <= 0)
output[i] = '?';//????????
else
l--;
}
else if (input[i] == '(')
l++;
}
l = r = 0;
for (i = len; i >= 0; --i)
{
if (input[i] == '(')
{
if (r <= 0)
output[i] = '$';//????????
else
r--;
}
else if (input[i] == ')')
r++;
}
cout << input << endl ;
cout<< output << endl ;//????
}
int main() {
while (cin.getline(input, 105)) {
f();
}
return 0;//????
}
|
17 | 8363 | char a[150];int l,j;
void left(int i){
int jj;
/*
cout << "left" << i << endl;
for (int j = 0; j < l; j++) {
cout << a[j];
}
cout << endl;*/
if(i==l-1){a[i]='$';return;}
for(jj=i+1;jj<l;jj++){
//cout << "for jj=" << jj << endl;
if(a[jj]==')'){
a[jj]=' ';
a[i]=' ';break;
}
else if(a[jj]=='('){left(jj);}
}
if (jj == l) {
a[i] = '$';
}
//cout << "return" << endl;
return;
}
void match(int i){//if(i==0){for(int k=0;k<l;k++)cout<<a[k];return;}
/*cout << i << endl;
for (int j = 0; j < l; j++) {
cout << a[j];
}
cout << endl;*/
if(i==l){
for(int ii=0;ii<l;ii++){
if(a[ii]=='('){a[ii]='$';}
if(a[ii]==')'){a[ii]='?';}
}
return;
}
else{
if(i==l-1&&a[i]=='('){a[i]='$';}
if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z')){a[i]=' ';}
else if(a[i]=='('){left(i);}
match(i+1);
}
}
int main(){
while(cin >> a){
l=strlen(a);for(int k=0;k<l;k++)cout<<a[k];cout<<endl;
match(0);for(int k=0;k<l;k++)cout<<a[k];cout<<endl;
}
return 0;
} |
17 | 8364 | int main()
{
while(true)
{
char a[110]={'\0'},b[110]={'\0'};
int i=0;
char x='\0';
while(true)
{
x=getchar();
if(x=='\n')break;
a[i]=x;
b[i]=x;
i++;
}
int k=1,j,n;
while(k<i)
{
for(j=0;j<i-k;j++)
{
int zhongjian=0,l;
if(k!=1)
{
for(l=j+1;l<j+k;l++)
{
if(a[l]=='(' || a[l]==')')zhongjian=1;
}
}
if(a[j]=='(' && a[j+k]==')' && zhongjian==0)
{
a[j]='\0';
a[j+k]='\0';
}
}
k=k+1;
}
for(n=0;n<i;n++)
{
if(a[n]=='(')a[n]='$';
else if(a[n]==')')a[n]='?';
else a[n]=' ';
}
for(n=0;n<i;n++)cout<<b[n];
cout<<endl;
for(n=0;n<i;n++)cout<<a[n];
cout<<endl;
}
return 0;
} |
17 | 8365 | int main ()
{
char sen[101];
int g[100] = {0}, left[100] = {0};
int m, n, i, k, sum;
while (cin.getline(sen,101))
{
n = strlen(sen);
k = 0;
sum = 0;
for (i = 0; i < n; i ++)
{
if (sen[i] == '(')
{
g[i] = 1;
sum ++;
left[k] = i;
k ++;
}
else
{
if (sen[i] == ')')
{
if (sum > 0)
{
sum --;
k --;
g[left[k]] = 0;
g[i] = 0;
}
else
{
g[i] = -1;
}
}
else
g[i] = 0;
}
}
for (i = n -1; g[i] == 0; i --)
{}
n = i;
for (i = 0; g[i] == 0; i ++)
{}
m = i;
cout << sen << endl;
for (i = m; i <= n; i ++)
{
if (g[i] == 1)
cout << '$';
else
{
if(g[i] == -1)
cout << '?';
else
cout << ' ';
}
}
cout << endl;
}
return 0;
}
|
17 | 8366 | int main()
{
char a[500]={0};
while(cin.getline(a,200))//????????
{
cout<<a<<endl;//????
int i,j,l=strlen(a);
for(i=0;i<l;i++)
{
if(a[i]==')')//??a[i]?)
{
for(j=i-1;j>=0;j--)
{
if(a[j]=='(')//??????(
{a[i]=a[j]=' ';break;} //????????
}
}
else if(a[i]=='(')continue;//????(,??
else a[i]=' '; //???a[i]????
}
for(i=0;i<l;i++)
{
if(a[i]=='(')cout<<'$';//???(,???
else if(a[i]==')')cout<<'?'; //???),??$
else cout<<' ';
}
cout<<endl;
}
return 0;
} |
17 | 8367 |
char a[110];
void match(int l)
{
if(a[l]=='\0') return;
int j;
if(a[l]==')')
{
for(j=l;j>=0;j--)
{
if(a[j]=='(')
{
a[l]=' ';
a[j]=' ';
break;
}
a[l]='?';
}
l++;
match(l);
}
else
{
l++;
match(l);
}
}
int main()
{
int i;
for(i=0;i<110;i++)
a[i]='\0';
while(cin.getline(a,101))
{
cout<<a<<endl;
for(i=0;a[i]!='\0';i++)
{
if(a[i]!='('&&a[i]!=')')
a[i]=' ';
}
match(0);
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='(')
a[i]='$';
}
for(i=0;a[i]!='\0';i++)
cout<<a[i];
cout<<endl;
for(i=0;a[i]!='\0';i++)
a[i]='\0';
}
return 0;
}
|
17 | 8368 |
int main(int argc, char* argv[])
{
int n,i,p,j,k,s,l;
char a[110],b[110]={' '};
scanf("%d",&n);
for (k=1;k<=n;k++)
{
s=0;
scanf("%s",&a);
l=strlen(a);
for (i=0;i<=l-1;i++)
{
if (a[i]=='(')
{
s+=1;
b[i]=' ';
continue;
}
else if (a[i]==')')
{
if (s>0)
{
s-=1;
b[i]=' ';
continue;
}
else if (s==0)
b[i]='?';
continue;
}
else
b[i]=' ';
continue;
}
s=0;
for (i=l-1;i>=0;i--)
{
if (a[i]==')')
{
s+=1;
continue;
}
else if (a[i]=='(')
{
if (s>0)
{
s-=1;
continue;
}
else if (s==0)
b[i]='$';
continue;
}
}
for (j=0;j<=l-1;j++)
{
printf("%c",a[j]);
}
printf("\n");
for (j=0;j<=l-1;j++)
{
printf("%c",b[j]);
}
printf("\n");
}
return 0;
}
|
17 | 8369 |
int main(){
int n,i,j,k,len,e;
char s[102];
scanf("%d",&n);
for(k=0;k<n;k++)
{
scanf("%s",&s);
len=strlen(s);
printf("%s\n",s);
for(j=0;j<len;j++){
if(s[j]!='(' && s[j]!=')'){s[j]=' ';}
}
for(i=len-1;i>=0;i--){
if(s[i]=='('){
for(e=i+1;e<len;e++){
if(s[e]==')'){
s[i]=' ';s[e]=' ';break;}
}
}
}
for(j=0;j<len;j++){
if(s[j]=='('){s[j]='$';}
if(s[j]==')'){s[j]='?';}
}
printf("%s\n",s);
}
return 0;
} |
17 | 8370 | char a[101];
int c[101];
void match(int i,int len){int k = i + 1;
if(c[i]!=0){ while(k<len){if(a[k]=='('&&c[k]==1){match(k,len);}
if(a[k]==')'&&c[i]==1&&c[k]==-1){c[i] = 0;c[k] = 0;}
k++;}}}
main(){int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%s",&a);
int len = strlen(a);
for(int j=0;j<len;j++){
if(a[j]=='('){c[j]=1;}
else if(a[j]==')'){c[j]=-1;}
else {c[j]=0;}}
for(int j=0;j<len;j++){if(c[j]==1){for(int k=j+1;k<len;k++){if(c[k]==1)break;
if(c[k]==-1){c[k]=0;c[j]=0;j=-1;break;}}}}
printf("%s\n",a);
for(int j=0;j<len;j++){if(c[j]==1)printf("$");
if(c[j]==-1)printf("?");
if(c[j]==0)printf(" ");}
printf("\n");}
}
|
17 | 8371 | int main()
{
char zfc[105];
char sign[105];
char present[105];
while(scanf("%s",zfc)>0)
{
//scanf("%s",zfc);
strcpy(sign,zfc);
strcpy(present,zfc);
int left=0,right=0;
int m=strlen(zfc);
for(int i=0;i<m;i++)
{
if(zfc[i]=='(')
{
left=0;
right=0;
for(int j=i;j<m;j++)
{
if(zfc[j]=='(')
{
left++;
}
if(zfc[j]==')')
{
left--;
}
if(left<=0)
{
break;
}
}
if(left>0)
{
sign[i]='$';
}
}
if(zfc[i]==')')
{
left=0;
right=0;
for(int j=i;j>=0;j--)
{
if(zfc[j]=='(')
{
right--;
}
if(zfc[j]==')')
{
right++;
}
if(right<=0)
{
break;
}
}
if(right>0)
{
sign[i]='?';
}
}
}
for(int i=0;i<m;i++)
{
if(sign[i]!='$'&&sign[i]!='?')
{
sign[i]=' ';
}
}
puts(present);
puts(sign);
}
return 0;
} |
17 | 8372 | int main()
{
char a[201],b[201],c[201];
int l,i,m,d[201],y,j;
while(scanf("%s",a)!=EOF)
{
l=strlen(a);
strcpy(b,a);
for(i=0;i<l;i++)
{
b[i]=' ';
}
strcpy(c,a);
loop:for(i=0;i<l;i++)
{
if(a[i]=='(')
{
for(j=i+1;j<l;j++)
{
if(a[j]=='(') break;
else
{
if(a[j]==')')
{
a[i]=a[j]='a';
goto loop;
}
}
}
}
}
for(i=0;i<l;i++)
{
if(a[i]=='(') b[i]='$';
if(a[i]==')') b[i]='?';
}
printf("%s\n%s\n",c,b);
}
} |
17 | 8373 | int main()
{
/*typedef struct _Parenthesis
{
char ch;
int idx;
} Parenthesis;*/
int LeftParenIndex[100];
char str[101];
while(gets(str))
{
int i,top=0;
puts(str);
for(i=0; str[i]; i++)
{
if(str[i] == '(')
LeftParenIndex[top++] = i;
else if(str[i] == ')')
{
if(top == 0)
str[i] = '?';
else
{
str[i] = ' ';
str[LeftParenIndex[--top]] = ' ';
}
}
else
str[i] = ' ';
}
for(i=0; i<top; i++)
str[LeftParenIndex[i]] = '$';
puts(str);
}
return 0;
} |
17 | 8374 |
int main()
{
int n;
cin>>n;
while(n--)
{
char s[105],a[105];
int i,k=0,stack[105];
memset(a,' ',sizeof(a));
cin>>s;
for(i=0;s[i]!='\0';i++)
if(s[i]=='(')
stack[k++]=-i-1;
else if(s[i]==')')
if(k==0 || stack[k-1]>0)
stack[k++]=i+1;
else
k--;
for(i=0;i<k;i++)
if(stack[i]>0)
a[stack[i]-1]='?';
else
a[-stack[i]-1]='$';
a[strlen(s)]='\0';
cout<<s<<endl
<<a<<endl;
}
return 0;
}
|
17 | 8375 | int main()
{
void match(char a[]);
int signal=1;
int i;
char s[101],s1[101]="";
gets(s);
while (signal)
{
match(s);
strcpy(s1,s);
scanf("%s",s);
if (strcmp(s,s1)==0)
signal=0;
}
return 0;
}
void match(char a[])
{
int i,j,k,len;
int f1=0,f2=0,f3=1;
len=strlen(a);
if (len!=0)
printf("%s\n",a);
do
{
if (len!=0)
{
f1=0;
f2=0;
f3=1;//??????
for (i=len-1;i>=0;i--)
{
if (a[i]=='(')
{
f1=1;//????????
for (j=i+1;a[j];j++)
{
if (a[j]==')')
{
f2=1;//??????????
a[j]='0';
a[i]='0';
break;
}
}
if (f2==0)//???????,a[i]?????
{
a[i]='1';
}
}
if (f1==1)
break;
}
if (f1==0)//???????
{
for (i=0;a[i];i++)
{
if (a[i]==')')//??????????2
{
a[i]='2';
}
}
}
for (i=0;a[i];i++)
{
if (a[i]=='('||a[i]==')')
{
f3=0;
break;
}
}
}
}while (f3==0);
for (i=0;a[i];i++)
{
if (a[i]=='1')
printf("$");
else if (a[i]=='2')
printf("?");
else
printf(" ");
}
printf("\n");
} |
17 | 8376 | int main()
{
char input[101]={0},initial[101];
int found=0;//????????
while (cin.getline(input,101))
{
strcpy(initial,input);
do
{
found=0;
int i=0,location=-1;
while (input[i])
{
if (input[i]=='(')
{
location=i;
found=1;
}
if (input[i]==')')
{
found=1;
if (location==-1) input[i]='?';
else
{
input[location]=' ';
input[i]=' ';
location=-1;
break;
}
}
if (input[i]!='?'&&input[i]!='$'&&input[i]!='('&&input[i]!=')') input[i]=' ';
i++;
}
if (location!=-1)
{
input[location]='$';
location=-1;
}
}
while (found);
cout <<initial <<endl <<input <<endl;
}
return 0;
} |
17 | 8377 | int main()
{
int n,i,j,k,l;
char a[100][120];
scanf("%d",&n);
getchar();
for(i=0;i<n;i++)
{
gets(a[i]);
puts(a[i]);
k=strlen(a[i]);
for(j=0;j<k;j++)
{
if(a[i][j]==')')
{
a[i][j]='?';
}
if(a[i][j]=='(')
{
a[i][j]='$';
}
}
for(j=0;j<k;j++)
{
if(a[i][j]!='?'&&a[i][j]!='$')
{
a[i][j]=' ';
}
}
for(j=0;j<k;j++)
{
if(a[i][j]=='?')
{
for(l=j;l>=0;l--)
{
if(a[i][l]=='$')
{
a[i][j]=' ';
a[i][l]=' ';
break;
}
}
}
}
for(j=0;j<k;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
}
return 0;
} |
17 | 8378 |
struct bracket
{
char data[max];
int top;
};
int main()
{
char str[max]={0}, flag[max]={0};
int i, len,n;
struct bracket *leftbracket, *rightbracket;
scanf("%d",&n);
while(n>0)
{while(scanf("%s", str) != EOF)
{
//????
leftbracket = (struct bracket *)malloc(sizeof(struct bracket));
rightbracket = (struct bracket *)malloc(sizeof(struct bracket));
leftbracket->top = rightbracket->top = 0;
len = strlen(str);
//?????????????
for(i = 0; i < len; i ++)
{
switch(str[i])
{
case '(' :
leftbracket->data[leftbracket->top ++] = str[i];
flag[i] = ' ';
break;
case ')' :
if(leftbracket->top > 0)
{
flag[i] = ' ';
leftbracket->top -= 1;
}else
{
flag[i] = '?';
}
break;
default :
flag[i] = ' ';
break;
}
}
//?????????????
for(i = len - 1; i >= 0; i --)
{
switch(str[i])
{
case ')' :
rightbracket->data[rightbracket->top ++] = str[i];
break;
case '(' :
if(rightbracket->top > 0)
{
rightbracket->top -= 1;
}else
{
flag[i] = '$';
}
break;
default :
break;
}
}
//????
printf("%s\n%s\n", str, flag);
//?????
memset(str, '\0', sizeof(str));
memset(flag, '\0', sizeof(flag));
}
n--;}
return 0;
}
|
17 | 8379 | int main()
{
char a[101];
int i,j,k,len;
while(scanf("%s",a)!=EOF)
{
puts(a);
len=strlen(a);
for(i=0;i<len;i++)
{
if(a[i]!='('&&a[i]!=')')
{
a[i]=' ';
}
else if(a[i]=='(')
{
for(j=i+1;j<len;j++)
{
if(a[j]=='(')
{
break;
}
else if(a[j]==')')
{
a[i]=' ';
a[j]=' ';
break;
}
}
}
else if(a[i]==')')
{
for(j=i-1;j>=0;j--)
{
if(a[j]=='(')
{
a[i]=' ';
a[j]=' ';
break;
}
else if(a[j]==')')
{
break;
}
}
}
}
for(i=0;i<len;i++)
{
if(a[i]=='(')
{
a[i]='$';
}
else if(a[i]==')')
{
a[i]='?';
}
}
puts(a);
}
return 0;
}
|
17 | 8380 | int main()
{
int n, i, j, len, c, zb[101], fb[101];
char a[101], s[101];
scanf("%d", &n);
for(i=0;i<n;i++)
{
scanf("%s", a);
len=strlen(a);
for(j=0;j<len;j++)
{
s[j]=a[j];
}
s[len] = '\0';
for(j=0;j<len;j++)
{
if(s[j]!='('&&s[j]!=')')
{
s[j]=' ';
}
}
int o=0, h=0;
for(j=0;j<len;j++)
{
if(s[j]=='(')
{
c=j;
zb[o]=j;
o++;
}
if(s[j]==')'&& o>0)
{
s[j]=' ';
s[c]=' ';
o--;
if(o > 0) c = zb[o - 1];
}
}
for(j=0;j<len;j++)
{
if(s[j]=='(')
{
s[j]='$';
}
if(s[j]==')')
{
s[j]='?';
}
}
printf("%s\n%s", a, s);
printf("\n");
}
return 0;
}
|
17 | 8381 |
int main()
{
char word[105],sign[105];
int num=0,i,len;
while(cin.getline(word,105))
{
num=0;
len=strlen(word);
for(i=0;i<len;i++)
sign[i]=' ';
for(i=0;i<len;i++)
{
if(word[i]=='(')
num++;
if(word[i]==')')
{
if(num>0)
num--;
else sign[i]='?';
}
}
num=0;
for(i=len-1;i>=0;i--)
{
if(word[i]==')')
num++;
if(word[i]=='(')
{
if(num>0)
num--;
else sign[i]='$';
}
}
sign[len]='\0';
cout<<word<<endl;
cout<<sign<<endl;
}
return 0;
}
|
17 | 8382 |
int function(char* out,int t)
{
int i=t;
if(out[i]=='(')
{
out[i]='$';
i++;
while(out[i]!=')'&&out[i])
{
if(out[i]=='(')
{
i=function(out,i)+1;
if(i==-1)return -2;
}
else
{
out[i]=' ';
i++;
}
}
if(out[i]==')')
{
out[t]=out[i]=' ';
return i;
}
else return -2;
}
else
{
while(out[i]!='('&&out[i])
{
if(out[i]==')')
out[i]='?';
else
out[i]=' ';
i++;
}
if(out [i]=='(')
return function(out,i);
else return -2;
}
}
int main()
{
char out[101];
int n=-1;
cin.getline(out,101);
while(out[0])
{
n=-1;
cout<<out<<endl;
while(n!=-2)
{
n=function(out,n+1);
}
cout<<out<<endl;
cin.getline(out,101);
}
return 0;
} |
17 | 8383 |
int main()
{
int i,j;
char a[101],b[101],c[101];
for(;;)
{
gets(a);
if(strcmp(c,a)==0) break;
for(i=0;a[i]!='\0';i++)
{
if(a[i]==')') b[i]='?';
else if(a[i]=='(') b[i]='$';
else b[i]=' ';
}
for(i=0;a[i]!='\0';i++)
{
if(b[i]=='?')
{
for(j=i;j>=0;j--)
{
if(b[j]=='$')
{ b[i]=' ';
b[j]=' ';
break;}
}
}
}
for(i=0;a[i]!='\0';i++)
printf("%c",a[i]);
printf("\n");
for(i=0;a[i]!='\0';i++)
printf("%c",b[i]);
printf("\n");
strcpy(c,a);
}
return 0;
}
|
17 | 8384 | int main()
{
char chn[120];
int i,l;
int z,t;
char a,b;
while(scanf("%s",chn)!=-1)
{
l = strlen(chn);
printf("%s\n",chn);
while(1)
{
z = -1;
t = 0;
for(i = 0;i < l; i++)
{
if(z == -1 && chn[i] == '(')
z = i;
else if(z >= 0 && chn[i] == ')')
{
chn[z] = ' ';
chn[i] = ' ';
t ++;
break;
}
else if(z >= 0 && chn[i] == '(')
z = i;
}
if(!t) break;
}
for(i = 0;i < l;i++)
{
if(chn[i] == '(')
chn[i] = '$';
else if(chn[i] == ')')
chn[i] = '?';
else chn[i] = ' ';
printf("%c",chn[i]);
}
printf("\n");
}
return 0;
}
|
17 | 8385 | main()
{
char s[101];//="12(((3))((7()888_)988((555)))))))";
int i,l,n,x,j,r;
int le[101]={0},ri[101]={0};
scanf("%d",&n);
for(x=0;x<n;x++)
{
for(i=0;i<100;i++)
{le[i]=0;ri[i]=0;}
scanf("%s",s);
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]=='(') le[i]=1;
if(s[i]==')') ri[i]=1;
}
for(i=l-1;i>=0;i--)
{
if(le[i]==1)
{
for(j=i;j<l;j++)
{
if(ri[j]==1)
{ri[j]=0;le[i]=0;break;}
}
}
}
puts(s);
for(i=0;i<l;i++)
{
if(ri[i]==1) printf("?");
if(le[i]==1) printf("$");
if(ri[i]==0&&le[i]==0) printf(" ");
}
printf("\n");
}
}
|
17 | 8386 | /* Name : ???????????
* Version : 2.0
* Date : 2012-11-24
* New : Null
* Func&Feat :
* State : Design
*/
int pairs(int,int,char text[],char match[]);
int main()
{
for(;;)
{
char text[101]={0},match[101]={0}; //???text????????match??????
int lgth=0; //???lgth??text???brkt[]????????????-1??????1?
gets(text); //??gets()??????????????????????
if(text[0]==0)break; //????????????????????
for(int i=0;i<101;i++) //???????text?????????????
{
if(text[i]!=0)
{
if(text[i]=='(')match[i]='$'; //??text[]?????brkt[]???-1?match[]????'$'
else if(text[i]==')')match[i]='?';//??text[]?????brkt[]???1?match[]????'?'
else match[i]=' '; //??text[]?????brkt[]?????0?match[]??????
}
else //??text[]?????????text?????
{
lgth=i;
break;
}
}
pairs(0,0,text,match);
cout<<text<<endl<<match<<endl;
}
return 0;
}
int pairs(int n,int hemi,char text[],char match[])
{
for(;;)
{
char c=text[n];
if(c==0)return -1;
if(c=='(')
{
int l=n;
int r=pairs(n+1,1,text,match);
// cout<<l<<' '<<r<<endl;
if(r!=-1)
{
match[l]=match[r]=' ';
n=r+1;
}
else return -1;
}
else if(c==')'&&hemi==1)return n;
else n++;
}
}
|
17 | 8387 | int main() {
int n;
cin >> n;
for ( int m = 1; m <= n; m ++ ) {
char str[105], str2[105];
cin >> str;
int stack[105];
int len = strlen( str ), k = 0;
for ( int i = 0; i < len; i ++ ) {
str2[i] = ' ';
}
str2[len] = '\0';
for ( int i = 0; i < len; i ++ ) {
if ( str[i] == ')' ) {
if ( k == 0 || stack[k - 1] > 0 ) {
stack[k ++] = i + 1;
}
else k --;
}
else if ( str[i] == '(' ) {
stack[k ++] = - i - 1;
}
}
for ( int i = 0; i < k; i ++ ) {
if ( stack[i] < 0 ) str2[-stack[i] - 1] = '$';
else str2[stack[i] - 1] = '?';
}
cout << str << endl;
cout << str2 << endl;
}
return 0;
} |
17 | 8388 | int main()
{
char a[120][102],b[120][102];
int n,i,j,k,r,d,l,cao;
for(i=1;i<=200;i++)
{
gets(a[i]);
if (strlen(a[i])==0)
break;
}
for(j=1;j<=i-1;j++)
{
for(k=0;k<=strlen(a[j])-1;k++)
{
if (a[j][k]==')')
{
if (k==0)
{
l=0;
}
for (r=0,cao=0;r<=k-1;r++)
{
if (a[j][r]=='(')
{
for(d=r+1,l=1;d<=k-1;d++)
{
if (a[j][d]==')')
l--;
else if (a[j][d]=='(')
l++;
}
if (l>0)
cao++;
}
}
if (cao>0)
b[j][k]=' ';
else
b[j][k]='?';
}
else if (a[j][k]=='(')
{
if (k==strlen(a[j])-1)
{
l=0;
}
for (r=k+1,cao=0;r<=strlen(a[j])-1;r++)
{
if (a[j][r]==')')
{
for(d=r-1,l=1;d>=k+1;d--)
{
if (a[j][d]=='(')
l--;
else if (a[j][d]==')')
l++;
}
if (l>0)
cao++;
}
}
if (cao>0)
b[j][k]=' ';
else
b[j][k]='$';
}
else
b[j][k]=' ';
}
}
for(j=1;j<=i-1;j++)
{
printf("%s\n%s\n",a[j],b[j]);
}
return 0;
} |
17 | 8389 | int main (void)
{
char a[100];
while(gets(a))
{
char ans[101];
for(int i=0;i<101;i++)
{
ans[i]=' ';
}
printf("%s\n",a);
int L=strlen(a);
ans[L]='\0';
int mark=0;
for(int i=L-1;i!=-1;i--)
{
if( a[i]=='(')
{
for(int j=i+1;;j++)
{
if(a[j]==')')
{
a[i]='0';
a[j]='0';
mark++;
break;
}
if(j==L)
{
a[i]='0';
ans[i]='$';
break;
}
}
}
}
for(int i=0;i<L;i++)
{
if(a[i]==')')
{
ans[i]='?';
}
}
printf("%s\n",ans);
}
return 0;
}
|
17 | 8390 | int main()
{
char a[101]={0}, b[101]={0};
int lef[101], r[101], i=0, j=0;
do{
cin.get(a,101);
cin.get();
if(a[0]=='\0')
break;
int len=strlen(a);
for(i=0; i<len; i++)
{
if(a[i]=='(')
b[i]='$';
else if(a[i]==')')
b[i]='?';
else
b[i]=' ';
}
for(i=0; i<len; i++)
if(b[i]=='?')
for(j=i; j>=0; j--)
if(b[j]=='$')
{
b[j]=' ';
b[i]=' ';
break;
}
for(i=0; i<len; i++)
cout<<a[i];
cout<<endl;
for(i=0; i<len; i++)
cout<<b[i];
cout<<endl;
}while(1);
return 0;
}
|
17 | 8391 | //*****************************************
//* ?????? *
//* ?????? *
//* ?????2011?12?17? *
//*****************************************
int main()
{
int i, j, n;
char a[200];
while(cin.get(a, 200))//???????
{
n = strlen(a);//????????
for(i = 0; i < n; i ++)
cout << a[i];//?????????
cout << endl;
for(i = 0; i < n; i ++)
{
if(a[i] == '(')
a[i] = '$';//?????????$
else if(a[i] == ')')
{
a[i] = '?';//??????????
for(j = i - 1; j >= 0; j --)//???????????
{
if(a[j] == '$')//?????????
{
a[i] = ' ';
a[j] = ' ';//?????????????
break;
}
}
}
else
a[i] = ' ';//??????????
}
for(i = 0; i < n; i ++)
cout << a[i];//?????????
cout << endl;
cin.get();//????????????
}
return 0;
} |
17 | 8392 | void main()
{
int b[101],t,n,i,j;
char a[101];
while(gets(a))
{
for(i=0;i<101;i++)
b[i]=0;
n=strlen(a);
for(i=0;i<n;i++)
{
if(a[i]=='(')
{
t=-1;
for(j=i+1;j<n;j++)
{
if(a[j]=='(')
{ t--;}
if(a[j]==')')
{ t++;}
if(t==0)break;
}
if(t<0)b[i]=1;
}
if(a[i]==')')
{
t=-1;
for(j=i-1;j>=0;j--)
{
if(a[j]=='(')
{ t++;}
if(a[j]==')')
{ t--;}
if(t==0)break;
}
if(t<0)b[i]=2;
}
}
for(i=0;i<n;i++)
printf("%c",a[i]);
printf("\n");
for(i=0;i<n;i++)
{
if(b[i]==0)printf(" ");
if(b[i]==1)printf("$");
if(b[i]==2)printf("?");
}
printf("\n");
}
}
|
17 | 8393 | int match (int);
int count (int);
int match (int,int,int,int);
char a[50][105],b[50][105]={0};
int num[50]={0};
int main ()
{
for (int i=0;;i++){
cin.getline (a[i],101);
count (i);
match (i);
cout<<a[i]<<endl;
cout<<b[i]<<endl;
}
return 0;
}
int count (int m) //???????
{
for (int i=0;a[m][i]!=0;i++)
num[m]++;
return 0;
}
int match (int k) //??????
{
for (int i=0;i<num[k];i++){
if (a[k][i]=='(') b[k][i]='$';
else if (a[k][i]==')') b[k][i]='?';
else b[k][i]=' ';
}
while (1){
int flag=-1,judge=0;
for (int i=0;i<num[k];i++){
if (b[k][i]=='$' && b[k][i+1]=='?') {
b[k][i]=' '; b[k][i+1]=' ';
judge=1;break;
}
else if (b[k][i]=='$' && b[k][i+1]==' ')
flag=i;
else if (b[k][i]=='?' && flag>=0)
{
b[k][i]=' '; b[k][flag]=' ';
flag=-1;judge=1;break;
}
}
if (judge==0)
break;}
return 0;
}
|
17 | 8394 | char st[100];
char st2[100];
int main()
{
memset(st,0,100);
memset(st2,0,100);
while(cin>>st)
{
int left=0,right=0;
int len=strlen(st);
for(int i=0;i<len;i++)
{
if(st[i]=='(')
left++;
if(st[i]==')')
right++;
if(left<right)
{
st2[i]='?';
right--;
}
}
left=0;
right=0;
for(int j=len-1;j>=0;j--)
{
if(st[j]=='(')
left++;
if(st[j]==')')
right++;
if(left>right)
{
st2[j]='$';
left--;
}
}
for(int i=0;i<len;i++)
{
if(st2[i]!='$'&&st2[i]!='?')
st2[i]=' ';
}
cout<<st<<endl;
cout<<st2<<endl;
memset(st,0,100);
memset(st2,0,100);
}
return 0;
} |
17 | 8395 | void change(char b[],int n,int m)
{
if(b[m]!=')'&&m<n)//????
{
change(b,n,m+1);
}
if(b[m]==')'&&m<n)
{
int i;
for(i=m;i>=0;i--)
{
if(b[i]=='(')
{
b[i]='A';
b[m]='A';
break;
}
}
change(b,n,m+1);
}
}
int main()
{
char a[200];
cin>>a;
getchar();
while(a[0]!=0)
{
int num,j;
num=strlen(a);
cout<<a<<endl;
change(a,num,0);
for(j=0;j<num;j++)//?????
{
if(a[j]=='(')a[j]='$';
else
{if(a[j]==')')
a[j]='?';
else
a[j]=' ';
}
}
cout<<a<<endl;
cin.getline(a,200);
}
return 0;
} |
17 | 8396 | main()
{
char s[101];
int i,a[101],j,l;
while((scanf("%s",s))!=EOF)
{
j=0;
puts(s);
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]=='(') a[++j]=i;
else if(s[i]==')')
{
if(j)
{
s[i]=' ';
s[a[j]]=' ';
j--;
}
else s[i]='?';
}
else s[i]=' ';
}
for(i=1;i<=j;i++) s[a[i]]='$';
puts(s);
}
}
|
17 | 8397 |
int main()
{
int i, l, flag=0, temp, z;
char a[1000];
while(gets(a)!=NULL){
printf("%s\n",a);
l=strlen(a);
for(z=1;z<=l;z++)
{ flag=0;
for(i=0;i<l;i++)
{
if(a[i]!='(' && a[i]!=')')
{
a[i]=' ';
}
if(a[i]=='(' )
{
flag=1;
temp=i;
}
if(a[i]==')' && flag==1)
{
a[i]=' ';
a[temp]=' ';
flag=0;
}
}}
for(i=0;i<l;i++)
{
if(a[i]=='(' )
a[i]='$';
if(a[i]==')' )
a[i]='?';
}
printf("%s\n",a);
}
return 0;
} |
17 | 8398 | int main() {
char s[200],s1[200];
int i, j;
int len;
while(gets(s)!=NULL) {
len = strlen(s);
strcpy(s1, s);
for(i=0; i<len; i++) {
if(s[i] == ')') {
for(j=i-1; j>=0; j--) {
if(s[j] == '(') {
break;
}
}
if(j >= 0) {
s[i] = ' ';
s[j] = ' ';
} else {
s[i] = '?';
}
} else if(s[i] != '(') {
s[i] = ' ';
}
}
for(i=0; i<len; i++) {
if(s[i] == '(') s[i] = '$';
}
puts(s1);
puts(s);
}
return 0;
}
|
17 | 8399 | int main(){
char a[101],b[101];
while(true){
cin.getline(a,101);
if(a[0]==0)break;
cout<<a<<endl;
int i,j=0,k,l,d;
for(i=0;i<strlen(a);i++)b[i]=' ';b[i]=0;
for(i=0;i<strlen(a);i++){
if(j==0&&a[i]==')')b[i]='?';
else if(a[i]==')'){
j--;
for(k=i;k>=0;k--){
if(b[k]=='$'){b[k]=' ';break;}
}
}
else if(a[i]=='('){j++;b[i]='$';}
}
for(d=0;d<strlen(a);d++)
if(b[d]!=' ')break;
for(i=0;i<strlen(a);i++)b[i]=b[i+d];
for(l=(strlen(a)-1-d);l>=0;l--)
if(b[l]!=' ')break;
b[l+1]=0;
cout<<b<<endl;
}
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.